Consulting

Results 1 to 4 of 4

Thread: Macro VBA "Save as" with bookmarks in file name string

  1. #1
    VBAX Newbie
    Joined
    Oct 2011
    Posts
    1
    Location

    Macro VBA "Save as" with bookmarks in file name string

    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

  2. #2
    VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,168
    Location
    This should fix you up.
    [VBA]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
    [/VBA]

  3. #3
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Cross-posted at: http://www.msofficeforums.com/vba/95...me-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!!!
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    VBAX Regular Kenny22's Avatar
    Joined
    Mar 2012
    Location
    wa - pERTH
    Posts
    7
    Location
    I'll have a play with this code..new to vba but enjoying the challenge pf trying other peoples suggested code...thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •