PDA

View Full Version : Macro VBA "Save as" with bookmarks in file name string



Dom37
10-27-2011, 02:54 AM
Goodmorning, i need create a macro VBA : Save as
my problem is insert in file name string a bookmark present in my active document. I make so:

/////////////////////////////////////////////////////////////////////
Sub SalvaNonConformita()

ChangeFileOpenDirectory "C:\Documenti\"

myDocname = ActiveDocument.Name

ActiveDocument.Bookmarks("CodAnom").Select

pos = InStr(myDocname, ".")

If pos > 0 Then

myDocname = Left(myDocname, pos - 1)

myDocname = "NonConformita_" & MyBookmark & ".doc"


ActiveDocument.SaveAs FileName:=myDocname, _
FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
End If

'ActiveDocument.Close

ChangeFileOpenDirectory "C:\Documenti\"
End Sub
////////////////////////////////////////////////////////////////////

where my bookmark is CodAnom

Please help me

Tommy
10-28-2011, 06:32 AM
This should fix you up.
Sub SalvaNonConformita()

ChangeFileOpenDirectory "C:\Documenti\"

myDocname = ActiveDocument.Name

ActiveDocument.Bookmarks("CodAnom").Select

pos = InStr(myDocname, ".")

If pos > 0 Then

myDocname = Left(myDocname, pos - 1)

myDocname = "NonConformita_" & ActiveDocument.Bookmarks("CodAnom").result & ".doc"


ActiveDocument.SaveAs FileName:=myDocname, _
FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
End If

'ActiveDocument.Close

ChangeFileOpenDirectory "C:\Documenti\"
End Sub

macropod
10-31-2011, 03:30 AM
Cross-posted at: http://www.msofficeforums.com/vba/9532-macro-vba-save-bookmarks-file-name-string.html

For cross-posting etiquette, please read: http://www.excelguru.ca/node/7

Like anyone else, I don't enjoy working out a solution only to find you've been given one (and not let on) somewhere else!!!

Kenny22
03-14-2012, 07:51 AM
I'll have a play with this code..new to vba but enjoying the challenge pf trying other peoples suggested code...thanks