noHandlebars
Technical User
Hi I'm trying to create a macro that will ask the user for input, then take that input and put it into the existing footer of a document, replacing what was previously in the footer.
This is what I have so far:
Sub FasterFindAndReplaceAllStoriesHopefully()
Dim myStoryRange As Range
Dim facilityName As String
Dim siteDate As String
'input boxes get facility and site date information
'facilityName = InputBox("Enter the correct facility name - location, st", "Facility Name Information", "Facility Name - Location, ST")
'siteDate = InputBox("Enter the correct site visit date (All Caps, First 3 Letters of Month)", "Site Visit Date Information", "JAN 1, 1111")
'First search the main document using the Selection
With Selection.Find
.Text = "FACILITY NAME - LOCATION, ST"
.Replacement.Text = "asdf"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
'Now search all other stories using Ranges
For Each myStoryRange In ActiveDocument.StoryRanges
If myStoryRange.StoryType <> wdMainTextStory Then
With myStoryRange.Find
.Text = "FACILITY NAME - LOCATION, ST"
.Replacement.Text = "asdf"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Do While Not (myStoryRange.NextStoryRange Is Nothing)
Set myStoryRange = myStoryRange.NextStoryRange
With myStoryRange.Find
.Text = "FACILITY NAME - LOCATION, ST"
.Replacement.Text = "asdf"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Loop
End If
Next myStoryRange
End Sub
Right now I have the input boxes disabled and just some dummy text for the replacement text. But when i run the macro nothing happens. Any suggestions on to why its not working?
This is what I have so far:
Sub FasterFindAndReplaceAllStoriesHopefully()
Dim myStoryRange As Range
Dim facilityName As String
Dim siteDate As String
'input boxes get facility and site date information
'facilityName = InputBox("Enter the correct facility name - location, st", "Facility Name Information", "Facility Name - Location, ST")
'siteDate = InputBox("Enter the correct site visit date (All Caps, First 3 Letters of Month)", "Site Visit Date Information", "JAN 1, 1111")
'First search the main document using the Selection
With Selection.Find
.Text = "FACILITY NAME - LOCATION, ST"
.Replacement.Text = "asdf"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
'Now search all other stories using Ranges
For Each myStoryRange In ActiveDocument.StoryRanges
If myStoryRange.StoryType <> wdMainTextStory Then
With myStoryRange.Find
.Text = "FACILITY NAME - LOCATION, ST"
.Replacement.Text = "asdf"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Do While Not (myStoryRange.NextStoryRange Is Nothing)
Set myStoryRange = myStoryRange.NextStoryRange
With myStoryRange.Find
.Text = "FACILITY NAME - LOCATION, ST"
.Replacement.Text = "asdf"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Loop
End If
Next myStoryRange
End Sub
Right now I have the input boxes disabled and just some dummy text for the replacement text. But when i run the macro nothing happens. Any suggestions on to why its not working?