Re: Problem with UserForm in Template

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Martyn,

I hate to say that the obvious problem is that you didn't do a very
good job of following the instructions.

Your:

Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks ("Text1")
.InsertBefore TextBox1
.Bookmarks ("Text2")
.InsertBefore TextBox2
End With

Is missing the essential ".Range" method and the line continuation
characters "_" that are shown in the example.

See:
http://word.mvps.org/FAQs/MacrosVBA/_AtEndOfLine.htm

and "Writing Visual Basic Statements" In VBA Help.



WembleyBear wrote:
I have created a template based on the suggestion at
http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

It all goes to plan except when it is executing the code for the button to
update the bookmarks on the template. My bookmarks are named as shown in the
example but the VB debugger gives an error on .Bookmarks of 'invalid use of
property'
Code is as follows:

Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks ("Text1")
.InsertBefore TextBox1
.Bookmarks ("Text2")
.InsertBefore TextBox2
End With

Any suggestions would be appreciated, in fairly newbie language please.

Martyn
Word 2000
Windows 2003 over Citrix XPe

.



Relevant Pages

  • Re: Macro to open new document and then switch back to old doc, word20
    ... spanning) the offending sentences. ... and it added the all the bookmarks at the start of the first offending ... Dim DestDoc As Document ' the document to receive text ... there is no mention of ActiveDocument or Selection other ...
    (microsoft.public.word.vba.general)
  • Re: Word 2004 Crashes on cut or copy or forward delete
    ... Daiya's into VBA now -- no place is now safe... ... While we know that no document can possibly contain two million bookmarks, ... That statement is not necessary in this particular macro. ... most people use "ActiveDocument" where speed doesn't matter. ...
    (microsoft.public.mac.office.word)
  • Re: Bookmarks are not retained during Mail Merge
    ... If you run the following macro when the mailmerge main document is active, ... datasource and then it will recreate the bookmarks that were in the main ... Set source = ActiveDocument ... Doug Robbins - Word MVP ...
    (microsoft.public.word.mailmerge.fields)
  • Re: VBA Copy Text with Selection - not Bookmark
    ... about the predefined bookmarks, see the VBA Help). ... Set OldDoc = ActiveDocument ... Set SrcRg = OldDoc.Bookmarks.Range ... order to activate the source document first since the Selection works on the ...
    (microsoft.public.word.vba.general)
  • Re: VBA Copy Text with Selection - not Bookmark
    ... about the predefined bookmarks, see the VBA Help). ... Set SrcRg = OldDoc.Bookmarks.Range ... order to activate the source document first since the Selection works on the ... > (still ActiveDocument) as the Source Range without much ado - how to ...
    (microsoft.public.word.vba.general)