Re: Accessing a TextBox

Tech-Archive recommends: Fix windows errors by optimizing your registry



I made up a new demo document with a table in the second section footer and
this time the macro works great. Still not sure why the tables in my
original document weren't recognized... but I am pretty sure I can solve this
by recreating the document if I have to.

Thanks again.
-------------

"Jim" wrote:

> Jay,
>
> This is really close, but for some reason, the procedure isn't recognizing
> the table which I still think is in the footer.
>
> In other words, this much works:
>
> ActiveDocument.Sections(2) _
> .Footers(wdHeaderFooterPrimary).Range = rng1
>
> When I add the .Tables(1) etc, the application tells me the requested member
> of the collection doesn't exist.
>
> I even added a new table into the footer to make sure there was really one
> there.
>
> Any suggestions on how I figure out for sure if my object is really a table
> in the footer? The table and its cells can't receive focus until the footer
> is active. Therefore I assume the table object is in the header. What am I
> missing?
>
> Thanks again,
>
> Jim
> =================
> "Jim" wrote:
>
> > Jay,
> >
> > Thanks for your prompt reply... this is just like I remember from the old
> > Compuserve days (a quick response). It looks like this is exactly what I
> > need, but I will post another response after I have tested it out.
> >
> > Thanks again,
> >
> > Jim
> >
> > "Jay Freedman" wrote:
> >
> > > Hi Jim,
> > >
> > > Your answers to the first four questions lead to this (it's all one
> > > statement, broken into separate lines with continuation characters):
> > >
> > > ActiveDocument.Sections(2) _
> > > .Footers(wdHeaderFooterPrimary).Range _
> > > .Tables(1) _
> > > .Cell(3, 4).Range _
> > > .Text = rng1
> > >
> > > The idea is that you "drill down" through successive layers of the
> > > object model: the document consists of sections, so you choose the
> > > second section; the section has a Footers collection, and you choose
> > > the primary footer; that footer has a range, which in turn contains a
> > > Tables collection...
> > >
> > > The answers to the other questions rule out the need for other
> > > complications, such as using the Format function to massage the
> > > appearance of the text.
> > >
> > > In formulating a statement like this, it helps to know which objects
> > > contain which collections. But my primary guide in this is the popups
> > > that list all the properties and methods of an object when you type
> > > the period after its name. Also, put the cursor on any of the keywords
> > > and press F1 to see its Help topic, which shows the parent-child
> > > relationships in a little diagram at the top. (That diagram is
> > > clickable and hyperlinks to the topics for those objects.)
> > >
> > > On Wed, 13 Apr 2005 18:51:02 -0700, Jim
> > > <Jim@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> > >
> > > >Jay,
> > > >
> > > >In answer to your questions:
> > > >> - Does the document contain more than one section? Yes If so, which section is
> > > >> the table in? 2
> > > >> - Is the table in the primary footer, rather than the first-page or
> > > >> even-page footer? It is a primary footer
> > > >> - Is it the only table in that footer? Yes
> > > >> - Which cell should the number be put into? Let's say for talking purposes, the cell is (3, 4). If I am off, I can adjust the number. Is it a particular cell in a
> > > >> known row and column, or do you have to find it by searching for something. No, I want to delete anything currently in this cell and replace it with the new number. (Actually a string such as T-12555).
> > > >> (if so, what?) See above.
> > > >> - Is the variable a number type (Integer, Single, etc.) or a String or a
> > > >> Variant? String
> > > >> - Does it need to be formatted in any special way (leading zeros, etc.)? This one has no leading zeros.
> > > >> - (least important) What's the name of the variable? I think I called it rng1
> > > >
> > > >Jay,
> > > >
> > > >Thanks for the personal attention. I am not used to this. I do appreciate
> > > >it. I have been learning word macros one baby step at a time. Figuring out
> > > >how to apply the object model is much different from Access or Excel VBA.
> > > >
> > > >Jim
> > > >
> > > >
> > > >"Jay Freedman" wrote:
> > > >
> > > >> Hi Jim,
> > > >>
> > > >> Need more details, please...
> > > >>
> > > >> - Does the document contain more than one section? If so, which section is
> > > >> the table in?
> > > >> - Is the table in the primary footer, rather than the first-page or
> > > >> even-page footer?
> > > >> - Is it the only table in that footer?
> > > >> - Which cell should the number be put into? Is it a particular cell in a
> > > >> known row and column, or do you have to find it by searching for something
> > > >> (if so, what?)
> > > >> - Is the variable a number type (Integer, Single, etc.) or a String or a
> > > >> Variant?
> > > >> - Does it need to be formatted in any special way (leading zeros, etc.)?
> > > >> - (least important) What's the name of the variable?
> > > >>
> > > >> --
> > > >> Regards,
> > > >> Jay Freedman
> > > >> Microsoft Word MVP FAQ: http://word.mvps.org
> > > >>
> > > >> Jim wrote:
> > > >> > I am trying to do something similar to what I see in Jay's answer,
> > > >> > but not quite the same. I am trying to paste a number I have stored
> > > >> > as a variable into a cell of a table which is embedded in a footer.
> > > >> > Any ideas on how to do this would be appreciated.
> > > >> >
> > > >> > "Jay Freedman" wrote:
> > > >> >
> > > >> >> Stefan_B wrote:
> > > >> >>> Hello,
> > > >> >>>
> > > >> >>> I have a textbox which sits in the header of a document, is their
> > > >> >>> anyway I can access the textbox, so that I may search the Header for
> > > >> >>> particulars pieces of text?
> > > >> >>>
> > > >> >>> Thanks,
> > > >> >>> Stefan.
> > > >> >>
> > > >> >> Hi Stefan,
> > > >> >>
> > > >> >> The following code assumes that "the header" means the primary
> > > >> >> header of section 1 (there could be first-page and/or even-page
> > > >> >> headers, or you could want a different section), that the header
> > > >> >> actually contains at least one shape object (a text box is a shape
> > > >> >> object), and that the first shape is the textbox you want to search.
> > > >> >> If any one of these assumptions isn't true, the On Error trap will
> > > >> >> be triggered and the macro will simply exit. In a real macro, you
> > > >> >> should test each assumption in turn and handle any problems
> > > >> >> appropriately.
> > > >> >>
> > > >> >> It also assumes you're just searching for the first occurrence of
> > > >> >> the text "find me" -- of course, that can be changed, and the search
> > > >> >> can be altered to become a replacement. All the interesting stuff is
> > > >> >> in the Set oRg statement.
> > > >> >>
> > > >> >> Sub foo()
> > > >> >> Dim oRg As Range
> > > >> >>
> > > >> >> On Error GoTo Bye
> > > >> >>
> > > >> >> Set oRg = ActiveDocument.Sections(1) _
> > > >> >> .Headers(wdHeaderFooterPrimary).Shapes(1) _
> > > >> >> .TextFrame.TextRange
> > > >> >>
> > > >> >> With oRg.Find
> > > >> >> .ClearFormatting
> > > >> >> .Format = False
> > > >> >> .Forward = True
> > > >> >> .Wrap = wdFindStop
> > > >> >> .Text = "find me"
> > > >> >> If .Execute Then
> > > >> >> oRg.Select
> > > >> >> End If
> > > >> >> End With
> > > >> >>
> > > >> >> Bye:
> > > >> >> End Sub
> > > >> >>
> > > >> >> --
> > > >> >> Regards,
> > > >> >> Jay Freedman
> > > >> >> Microsoft Word MVP FAQ: http://word.mvps.org
> > > >>
> > > >>
> > > >>
> > >
> > >
> > > --
> > > Regards,
> > > Jay Freedman
> > > Microsoft Word MVP FAQ: http://word.mvps.org
> > >
.



Relevant Pages

  • Re: Accessing a TextBox
    ... Compuserve days (a quick response). ... "Jay Freedman" wrote: ... > Hi Jim, ... > the primary footer; that footer has a range, ...
    (microsoft.public.word.vba.general)
  • Re: Accessing a TextBox
    ... "Jay Freedman" wrote: ... > Hi Jim, ... > the primary footer; that footer has a range, ... >>> Regards, ...
    (microsoft.public.word.vba.general)
  • Re: Printing headers and footers in vb.NET
    ... "Jim" wrote in message ... Counting the pages is not a big deal but the footer is driving me crazy. ... My reasearch only has gotten me bits and pieces of information, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Accessing a TextBox
    ... I even added a new table into the footer to make sure there was really one ... "Jim" wrote: ... >> the primary footer; that footer has a range, ... >> relationships in a little diagram at the top. ...
    (microsoft.public.word.vba.general)
  • Re: Printing with no margins (footer)
    ... You and Jay are the only individuals that knew what the issue is. ... (presumably anchored to the footer). ... regardless of how margins or indents are set. ... A PRINTER it displays (ie. the second image I provided). ...
    (microsoft.public.word.pagelayout)