View Single Post
 
Old 06-07-2017, 08:19 PM
Beatle13 Beatle13 is offline Windows 10 Office 2010 64bit
Novice
 
Join Date: Jun 2017
Posts: 2
Beatle13 is on a distinguished road
Default Add {mergefieldnumber} to save name

Hi all,

The code below was written by a previous employee and have very little experience doing VBA programming.
Help how this should be written would of great assistance, to gmayor, how to do what you have below i have no idea.

I am trying to edit a VBA macro to add the {MERGEfIELD number} to the save file name.
the macro below is what I have but this only saves the file as Selectronic Purchase Order.doc.

the document data looks like this
Order Number: { MERGEFIELD number } Date: { MERGEFIELD date }
Order Number: 130465 Date: 07/06/2017

any help with this would save time and errors.

Sub OpenPurchaseOrdersSean()
'
' OpenPurchaseOrdersSean Macro
'
'
'
'
WordBasic.FileOpen Name:="c:\flexsoft\poprint."
WordBasic.FileSaveAs Name:="c:\flexsoft\Poprint.doc", Format:=0, LockAnnot:=0, Password:="", AddToMru:=1, WritePassword:="", RecommendReadOnly:=0, EmbedFonts:=0, NativePictureFormat:=0, FormsData:=0, SaveAsAOCELetter:=0

' Search and replace " characters
WordBasic.StartOfDocument
WordBasic.StartOfLine
WordBasic.EditFind Find:=Chr(34), Direction:=0, MatchCase:=0, WholeWord:=0, PatternMatch:=0, SoundsLike:=0, Format:=0, Wrap:=0
While WordBasic.EditFindFound()
WordBasic.InsertSymbol Font:="Symbol", CharNum:="178"
WordBasic.EditFind Find:=Chr(34), Direction:=0, MatchCase:=0, WholeWord:=0, PatternMatch:=0, SoundsLike:=0, Format:=0, Wrap:=0
Wend
' Search and replace ² characters
WordBasic.StartOfDocument
WordBasic.StartOfLine
WordBasic.EditFind Find:="ý", Direction:=0, MatchCase:=0, WholeWord:=0, PatternMatch:=0, SoundsLike:=0, Format:=0, Wrap:=0
While WordBasic.EditFindFound()
Selection.InsertSymbol CharacterNumber:=178, Unicode:=True
WordBasic.EditFind Find:="ý", Direction:=0, MatchCase:=0, WholeWord:=0, PatternMatch:=0, SoundsLike:=0, Format:=0, Wrap:=0
Wend
WordBasic.FileSave
WordBasic.FileClose
WordBasic.FileOpen Name:="U:\Purchasing\Sean\Selectronic Purchase Order.doc", ConfirmConversions:=0, ReadOnly:=0, AddToMru:=0, PasswordDoc:="", PasswordDot:="", Revert:=0, WritePasswordDoc:="", WritePasswordDot:=""
End Sub

Last edited by Beatle13; 06-08-2017 at 01:22 AM.
Reply With Quote