Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Problem with UserForm in Template

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WembleyBear - 15 Nov 2006 16:26 GMT
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
Jay Freedman - 15 Nov 2006 16:42 GMT
You have split two of the statements into two lines each, where they must be
one line in order to work.

Change to this:

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

Signature

Regards,
Jay Freedman
Microsoft Word MVP     FAQ: http://word.mvps.org

>I have created a template based on the suggestion at
> http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
[quoted text clipped - 20 lines]
> Word 2000
> Windows 2003 over Citrix XPe
Greg Maxey - 15 Nov 2006 16:51 GMT
Jay,

Adding .Range will help too ;-)

> You have split two of the statements into two lines each, where they must be
> one line in order to work.
[quoted text clipped - 37 lines]
> > Word 2000
> > Windows 2003 over Citrix XPe
Jay Freedman - 15 Nov 2006 17:48 GMT
Yes, you're right. I'm working today on a machine without Office, so maybe I
should just keep my head down...

Signature

Regards,
Jay Freedman
Microsoft Word MVP     FAQ: http://word.mvps.org

> Jay,
>
[quoted text clipped - 45 lines]
>> > Word 2000
>> > Windows 2003 over Citrix XPe
Greg Maxey - 15 Nov 2006 17:59 GMT
Jay,

Now I am really baffled.  Martyn stated that "Thanks but as Jay pointed
out, the Range part of the statement is not needed in this instance
(and I don't need it for my purposes either);..."

That would lead me to believe that there must be more to Martyn's code
than he has posted or his concept of not needed is different than mine.
Based on the code that he has shown, I don't see how it could possible
work.

> Yes, you're right. I'm working today on a machine without Office, so maybe I
> should just keep my head down...
[quoted text clipped - 53 lines]
> >> > Word 2000
> >> > Windows 2003 over Citrix XPe
Jay Freedman - 15 Nov 2006 21:13 GMT
Agreed. If Martyn has tried to run his code, he'll find that it stops with a
compile error.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Jay,
>
[quoted text clipped - 65 lines]
>>>>> Word 2000
>>>>> Windows 2003 over Citrix XPe
WembleyBear - 15 Nov 2006 17:00 GMT
Doh! Thanks Jay, that part works perfectly now. However the Autonew macro
doesn't start automatically when I open the template - it only starts if I
actually run the macro in the template. Again, I have put in the code as
shown in the example....

Sub autonew()
'
' autonew Macro
' Macro created 15/11/2006 by mgr060
'

UserForm1.Show

End Sub

> You have split two of the statements into two lines each, where they must be
> one line in order to work.
[quoted text clipped - 32 lines]
> > Word 2000
> > Windows 2003 over Citrix XPe
Greg Maxey - 15 Nov 2006 16:50 GMT
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
[quoted text clipped - 3 lines]
>   .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.

> I have created a template based on the suggestion at
> http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
[quoted text clipped - 18 lines]
> Word 2000
> Windows 2003 over Citrix XPe
WembleyBear - 15 Nov 2006 17:05 GMT
Greg

Thanks but as Jay pointed out, the Range part of the statement is not needed
in this instance (and I don't need it for my purposes either); and the
example on the site is set out particularly poorly. Fortunately, I'm not a
total idiot....

Martyn :-)

> Martyn,
>
[quoted text clipped - 41 lines]
> > Word 2000
> > Windows 2003 over Citrix XPe
Greg Maxey - 15 Nov 2006 17:34 GMT
Martyn,

I note your smile, but still want to say that I didn't mean to imply
you where an idiot at all and apologize for coming across that way to
you or anyone else reading this thread.  I'm sorry.

Hmm...I get an compile error "Method or data member not found" if I
exclude the .Range part.  I sense I am about to be schooled ;-)

> Greg
>
[quoted text clipped - 50 lines]
> > > Word 2000
> > > Windows 2003 over Citrix XPe

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.