Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-29-2015, 05:32 PM
tddfs tddfs is offline Send Userform Text to Bookmark Windows 7 32bit Send Userform Text to Bookmark Office 2007
Novice
Send Userform Text to Bookmark
 
Join Date: Jul 2015
Posts: 3
tddfs is on a distinguished road
Default Send Userform Text to Bookmark

I'm trying to do something similar to https://www.msofficeforums.com/word-...nt-header.html (at least it sounds similar) and also running into the same type of problems. I have userform that pops up when the template is opened but the command button leads to runtime error 5941

Code:
Private Sub CommandButton1_Click()
 
With ActiveDocument
    .Bookmarks("Text1").Range.Text = TextBox1
    .InsertBefore TextBox1
    .Bookmarks("Text2").Range.Text = TextBox2
    .InsertBefore TextBox2
End With
 
UserForm1.Hide
 
End Sub
I've been using a macro to open the userform.



Code:
Sub autonew()
'
' autonew Macro
'
'
UserForm1.Show
End Sub
Any help would be appreciated.

Last edited by macropod; 07-29-2015 at 05:55 PM. Reason: Split from unrelated thread
Reply With Quote
  #2  
Old 07-29-2015, 05:44 PM
macropod's Avatar
macropod macropod is offline Send Userform Text to Bookmark Windows 7 64bit Send Userform Text to Bookmark Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I don't get error 5941 but both your .InsertBefore methods quite understandably generate error 438, as they have no Range context. Besides, which, I can't see why you'd want both '.Text = TextBox1' and '.InsertBefore TextBox1', since it seems you're trying to do the same thing with both (i.e. duplicating the output). Furthermore, there are better ways to populate bookmarks; see, for example: https://www.msofficeforums.com/word-vba/21845-cross-referencing-bookmarks-populated-userform-word-2010-a.html#post67058
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-30-2015, 09:43 AM
tddfs tddfs is offline Send Userform Text to Bookmark Windows 7 32bit Send Userform Text to Bookmark Office 2007
Novice
Send Userform Text to Bookmark
 
Join Date: Jul 2015
Posts: 3
tddfs is on a distinguished road
Default

I read your input over and changed to this

Code:
Private Sub CommandButton1_Click()

With ActiveDocument
    .Range.Text = TextBox1
End With

UserForm1.Hide

End Sub
This is working fine, but the reason I was using bookmarks was to place the text input into a specific place within the document (actually 3 places). So I was wondering if there is a better way other than bookmarks? I'm going to work with fields to see if that can achieve the goal, but right now bookmarks appear to be the best bet. Thanks
Reply With Quote
  #4  
Old 07-30-2015, 02:59 PM
macropod's Avatar
macropod macropod is offline Send Userform Text to Bookmark Windows 7 64bit Send Userform Text to Bookmark Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I can't see that what you've done is anything like the link I provided suggests. And no, you don't have to use bookmarks but, whatever method you use has to be specific - you could write to a content control, a custom document property, a table cell, a specified paragraph (via its index #), etc., etc.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-30-2015, 03:51 PM
tddfs tddfs is offline Send Userform Text to Bookmark Windows 7 32bit Send Userform Text to Bookmark Office 2007
Novice
Send Userform Text to Bookmark
 
Join Date: Jul 2015
Posts: 3
tddfs is on a distinguished road
Default

Hi: I worked on that before I found the thread with the link. Not sure why I did not see your post??

The code from the link - Sub UpdateBookmark - It seem as though a custom document property would be the best, but I don't see how it ties into the code from the link?

Reviewing your link I was hoping this would work

Code:
Private Sub CommandButton1_Click()
 
Dim MyProp As Range
Dim StrTxt As String
 
With ActiveDocument
 
   Set MyProp = TextBox1
   MyProp.Text = StrTxt
   .Fields.Update
 
 
End With
 
UserForm1.Hide
 
End Sub
Still not working though I would like to think my thought process is correct based on what you have done in the prior link.

On the bright side my error code is now 13 so at least that is going down.

I set up a DOCPROPERTY called MyProp as the placeholder in the word document
Reply With Quote
  #6  
Old 07-30-2015, 05:55 PM
macropod's Avatar
macropod macropod is offline Send Userform Text to Bookmark Windows 7 64bit Send Userform Text to Bookmark Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by tddfs View Post
The code from the link - Sub UpdateBookmark - It seem as though a custom document property would be the best, but I don't see how it ties into the code from the link?
Well, given that the code in the link is for updating a bookmark, which is what your initial post was apparently trying to do, one shouldn't expect it to work with a custom document property. Have you even looked at any code samples dealing with writing to custom document properties or variables? For example, to add and update :
Custom Document Properties, see: http://support.microsoft.com/kb/212618/
Document Variables, see: http://support.microsoft.com/kb/306281/
Quote:
Originally Posted by tddfs View Post
Reviewing your link I was hoping this would work
Still not working though I would like to think my thought process is correct based on what you have done in the prior link.
I can't see how you could think the code you've posted has anything to do with what's in the link, or with updating a custom document property.

I think you need to spend a little time working out how one uses the various methods available for populating a document. When you decide what you want to work with, be that a bookmark, a content control, a custom document property, a table cell, a specified paragraph (via its index #), etc., then stick with code related to that method rather than trying to use code designed for something else.

As for:
Quote:
On the bright side my error code is now 13 so at least that is going down.
That suggests you don't understand what error codes are about...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Send Userform Text to Bookmark Moving Selected Items from a Multiselect Listbox on a userform to a bookmark in Word marksm33 Word VBA 3 01-15-2015 07:55 PM
Send Userform Text to Bookmark send a string from Excel UserForm to Word saltlakebuffalo Excel Programming 1 02-10-2014 11:01 PM
Repeating Bookmark Text BECKTHOMO Word 1 03-27-2012 08:34 PM
Send Userform Text to Bookmark Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control skarden Word 1 12-12-2011 10:39 PM
Send Userform Text to Bookmark delete all bookmark text hklein Word VBA 4 08-10-2011 04:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft