|
-
Mar 22nd, 2006, 09:13 AM
#1
[RESOLVED] Programmatically Updating Footer In Word Document
I have a Word document that will be utilized as a Template.
I have the following place holders as a Footer:
Originator:
Use Cases For:
What I would like to do is prompt the user for his/name and, once entered, update the footer information so that after entering the name, the footer would read:
Originator: Hack
I would like to do the same thing for the second line as well.
I guess my first question would be is this even possible?
-
Mar 22nd, 2006, 10:34 AM
#2
Frenzied Member
Re: Programmatically Updating Footer In Word Document
Hack:
I don't claim to be a Pro in Word, but here is something I recorded and then munged with. It seems to work ... except that it doesn't close the Header/Footer view. You can figure that out. Just do whatever you need to do to set up the 2 tStr variables that get inserted into the Footer.
Code:
Sub Macro3()
Dim tStr1 As String
Dim tStr2 As String
'
tStr1 = "Hack"
tStr2 = "This is a TEST"
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Originator:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" " & tStr1
With Selection.Find
.Text = "Use Cases For:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" " & tStr2
End Sub
I hope this helps!
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Mar 22nd, 2006, 10:48 AM
#3
Re: Programmatically Updating Footer In Word Document
Hack
Basically you will need a variable in the document that can contain each of these values. The easiest way I have found to do this in the past is to use the "Custom Document Properties" feature in Word.
Goto File-->>Properties and select the custom tab. Here you can add any properties you need, e.g. Originator. The in your _Open event, you can check to see if that property has a value other than a single space (it has to have some value, space is a good default) and prompt for one if its missing.
VB Code:
Private Sub Document_Open()
Dim MyProp As DocumentProperty
For Each MyProp In ThisDocument.CustomDocumentProperties
With MyProp
If .Name = "Originator" Then
If .Value = " " Then
'get your value here,
'updating the value property
' and update header/footer
End If
End If
End With
Next MyProp
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 22nd, 2006, 12:33 PM
#4
Re: Programmatically Updating Footer In Word Document
Two questions:
Once I get a value for Originator, how do I tell it to update the Footer with that value?
Does Word VBA support the InputBox?
-
Mar 22nd, 2006, 12:42 PM
#5
Re: Programmatically Updating Footer In Word Document
 Originally Posted by Hack
Two questions:
Once I get a value for Originator, how do I tell it to update the Footer with that value?
Does Word VBA support the InputBox?
Strike the InputBox question. I have that working and I have a name stored in a string.
I just don't know what to do with it in order to make it show up in the footer as:
Originator: Name_I_Typed
-
Mar 22nd, 2006, 01:26 PM
#6
Re: Programmatically Updating Footer In Word Document
Webtest has posted the code necessary for accessing the header or footer.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 22nd, 2006, 01:32 PM
#7
Re: Programmatically Updating Footer In Word Document
Incidentally, you can use document variables to store anything you need - just like a variable but stored in the document.
VB Code:
ActiveDocument.Variables.Add Name:="Value1", Value:="1"
MsgBox ActiveDocument.Variables("Value1")
I find them much easier to use than custom properties. Also, you can put them straight into a document using the DOCVARIABLE field. So I'd just insert a DOCVARIABLE field into your footer and then prompt the user for their name (or copy the string) into that document variable, then just update the fields. You could easily do the same for the second case too.
zaza
Last edited by zaza; Mar 22nd, 2006 at 01:35 PM.
-
Mar 22nd, 2006, 01:52 PM
#8
Re: Programmatically Updating Footer In Word Document
 Originally Posted by RobDog888
Webtest has posted the code necessary for accessing the header or footer. 
So he has, and it works.
Ok...final question...how do I automatically close the Header/Footer view?
-
Mar 22nd, 2006, 01:54 PM
#9
Re: Programmatically Updating Footer In Word Document
Something like so.
VB Code:
ActiveWindow.ActivePane.View.Type = wdPrintView
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 22nd, 2006, 01:55 PM
#10
Frenzied Member
Re: Programmatically Updating Footer In Word Document
WUZZAMATTA Hack ... you don't like the code I dished up especially for you?
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Mar 22nd, 2006, 01:56 PM
#11
Frenzied Member
Re: Programmatically Updating Footer In Word Document
Record a macro while you close the Header/Footer view. I did nearly the whole code in my post in Record Macro! (That's why it looks so kludgy!)
Edit: RobDog made it too easy for you!
Thanks, RobDog!
Last edited by Webtest; Mar 22nd, 2006 at 02:00 PM.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Mar 22nd, 2006, 01:58 PM
#12
Re: Programmatically Updating Footer In Word Document
And I plagerized it in my previous post
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 22nd, 2006, 02:09 PM
#13
Re: Programmatically Updating Footer In Word Document
 Originally Posted by Webtest
WUZZAMATTA Hack ... you don't like the code I dished up especially for you?
I love your code, am using it.
-
Mar 22nd, 2006, 02:11 PM
#14
Re: Programmatically Updating Footer In Word Document
 Originally Posted by Webtest
Edit: RobDog made it too easy for you!
I'm sure I could have figured it out, but after all this time I felt that it was my turn to play noob. 
It actually felt kinda good.
-
Mar 22nd, 2006, 05:58 PM
#15
Re: [RESOLVED] Programmatically Updating Footer In Word Document
Glad I'm not the only one that gets to feel like a noob. Currently being a noob at ASP.NET 
Ps Hack - 22,222 posts
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|