francozola25
07-21-2008, 05:56 AM
Hello
I was wondering if someone could help me. I am currently using inproperty fields in my macro to input a value into a usefrom textbox and update all inbuiltproperties field with that value.
I want to add another textbox called TextBox2 to my userform and do the same again but this time i want to use bookmarks.
I have tried numerous times but can't seem to get it to work please
Please see code
Set bDoc = Documents.Open("\\myserver\Forms\" & ExcelFN & ".Doc", ReadOnly:=True, Visible:=False)
'Set Title of aDoc = bDoc
bDoc.BuiltInDocumentProperties("Title") = _
aDoc.BuiltInDocumentProperties("Title")
Call UpdateStoryRanges(bDoc)
Call FillABookmark(bDoc, "here", TextBox2)
Sub UpdateStoryRanges(CurrentDoc As Document)
Dim oStory As Range
'Loop to update the main body of the document
For Each oStory In CurrentDoc.StoryRanges
Application.StatusBar = ""
'Update the all the FormFields
oStory.Fields.Update
Application.StatusBar = ""
If oStory.StoryType < wdMainTextStory Then
'Loop through main body of document until all fields are updated
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Application.StatusBar = ""
Wend
End If
Next oStory
Application.StatusBar = ""
Set oStory = Nothing
End Sub
Sub FillABookmark(CurrentDoc As Document, strBM As String, strText As String)
Dim oRange As Word.Range
Set oRange = CurrentDoc.Bookmarks(strBM).Range
CurrentDoc.Bookmarks(strBM).Range.Text = strText
With oRange
.Collapse Direction:=wdCollapseEnd
.MoveEnd Unit:=wdCharacter, Count:=Len(strText)
End With
CurrentDoc.Bookmarks.Add strBM, Range:=oRange
End Sub
I am opening files and updating the bookmarks.
i have inserted a bookmark called here before hand and saved. When i run the macro it does not input the value and i can't understand why.
I was wondering if someone could help me. I am currently using inproperty fields in my macro to input a value into a usefrom textbox and update all inbuiltproperties field with that value.
I want to add another textbox called TextBox2 to my userform and do the same again but this time i want to use bookmarks.
I have tried numerous times but can't seem to get it to work please
Please see code
Set bDoc = Documents.Open("\\myserver\Forms\" & ExcelFN & ".Doc", ReadOnly:=True, Visible:=False)
'Set Title of aDoc = bDoc
bDoc.BuiltInDocumentProperties("Title") = _
aDoc.BuiltInDocumentProperties("Title")
Call UpdateStoryRanges(bDoc)
Call FillABookmark(bDoc, "here", TextBox2)
Sub UpdateStoryRanges(CurrentDoc As Document)
Dim oStory As Range
'Loop to update the main body of the document
For Each oStory In CurrentDoc.StoryRanges
Application.StatusBar = ""
'Update the all the FormFields
oStory.Fields.Update
Application.StatusBar = ""
If oStory.StoryType < wdMainTextStory Then
'Loop through main body of document until all fields are updated
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Application.StatusBar = ""
Wend
End If
Next oStory
Application.StatusBar = ""
Set oStory = Nothing
End Sub
Sub FillABookmark(CurrentDoc As Document, strBM As String, strText As String)
Dim oRange As Word.Range
Set oRange = CurrentDoc.Bookmarks(strBM).Range
CurrentDoc.Bookmarks(strBM).Range.Text = strText
With oRange
.Collapse Direction:=wdCollapseEnd
.MoveEnd Unit:=wdCharacter, Count:=Len(strText)
End With
CurrentDoc.Bookmarks.Add strBM, Range:=oRange
End Sub
I am opening files and updating the bookmarks.
i have inserted a bookmark called here before hand and saved. When i run the macro it does not input the value and i can't understand why.