Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2017, 08:19 PM
Beatle13 Beatle13 is offline Add {mergefieldnumber} to save name Windows 10 Add {mergefieldnumber} to save name Office 2010 64bit
Novice
Add {mergefieldnumber} to save name
 
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
  #2  
Old 06-07-2017, 10:49 PM
gmayor's Avatar
gmayor gmayor is offline Add {mergefieldnumber} to save name Windows 10 Add {mergefieldnumber} to save name Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Word Basic? It has been a seriously long time since I used that, and its continued use has built-in obsolescence. I seem to recall that it is not fully supported in the most recent Word versions, but don't hold me to it.

Once the document has been merged the fields are replaced with the merge data, so you would have to split the line and delete the redundant information to get the required data.

Frankly I would bring your process kicking and screaming into the 21st century and use
http://www.gmayor.com/individual_merge_letters.htm. or

http://www.gmayor.com/MergeAndSplit.htm

to name your document from the data, with or without added text.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 06-12-2017, 07:14 PM
Beatle13 Beatle13 is offline Add {mergefieldnumber} to save name Windows 10 Add {mergefieldnumber} to save name Office 2010 64bit
Novice
Add {mergefieldnumber} to save name
 
Join Date: Jun 2017
Posts: 2
Beatle13 is on a distinguished road
Default New to this

How do I go about bring this into the 21st century, this was built by a past employee and know very little about VBA.
I know how to record macros but this is way above my learning.
Reply With Quote
  #4  
Old 06-12-2017, 08:03 PM
gmayor's Avatar
gmayor gmayor is offline Add {mergefieldnumber} to save name Windows 10 Add {mergefieldnumber} to save name Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

No knowledge of macros is required if you use one of my add-ins, which will work with Word versions from 2007 to the present version.

If there are multiple record items per letter i.e. a Many to One merge then see http://www.gmayor.com/ManyToOne.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2016 Won't Save. Keeps Asking to Save As, But Doesn't CrossReach Word 3 03-11-2017 05:23 PM
Add {mergefieldnumber} to save name Macro to save as pdf with ability to choose save as folder rvessio Word VBA 4 07-25-2016 12:37 PM
Add {mergefieldnumber} to save name save dialog box promt doesn't save file brmveen Word VBA 2 11-04-2015 12:51 AM
Add {mergefieldnumber} to save name When I try to save an existing word doc, save as pops up and will not save... samanthab Word 3 01-19-2013 06:27 AM
Word ask to save template whenever i save a derived document jorbjo Word 3 10-04-2012 10:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:23 AM.


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