Consulting

Results 1 to 3 of 3

Thread: Save As Macro that changes the file name also

  1. #1

    Save As Macro that changes the file name also

    Hello,

    I have a template letter document, called A-D contract, with a userform that inserts text at the correct bookmarks.

    I have recorded a macro that saves the file to a specific folder( easy enough) but I, if possible, I would like to include some code that changes the name of the file when I run the macro. For example, LastName,FirstName Contract -Blogs,Joe-Contract.docm

    So, I don't have to go Save As, Find folder and then type over the template name

    Someone has give me this but it doesn't seem to like the ME.

    If should maybe point out that in the form I am using a txt called txtEmployeeName ( not sure if this is relevant)

    Any input would be welcomed.

    Thanks

    Ross



    Sub SaveAS()
    '
    ' SaveAS Macro
    '
    
    Dim NewFileName As String
    Dim NewFilePath As String
    
    
    NewFilePath = "H:\HR\Reward & Shared Services\Shared Services Only\1 ~ Starters\3 ~ Contract Templates\DB Templates\"
    NewFileName = Me.txtLastName & "," & Me.txtFirstName & ",Contract.docm"
    
    '
    ChangeFileOpenDirectory _
    "H:\HR\Reward & Shared Services\Shared Services Only\1 ~ Starters\3 ~ Contract Templates\DB Templates\"
    ActiveDocument.SaveAs2 FileName:= _
    "H:\HR\Reward & Shared Services\Shared Services Only\1 ~ Starters\3 ~ Contract Templates\DB Templates\A-D contract v10-MACRO.docm" _
    , FileFormat:=wdFormatXMLDocumentMacroEnabled, LockComments:=False, _
    Password:="", AddToRecentFiles:=True, WritePassword:="", _
    ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    False, CompatibilityMode:=14
    End Sub
    Last edited by Bob Phillips; 05-14-2014 at 12:49 AM. Reason: Added VBA tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Me refers to the container object. Presumably, whoever wrote this code included it within the userform, so the Me refers to that form. Me.txtLastName is the textbox with that part of the name, etc., If you are not using the code within the form, you need to change those parts of the code to wherever you have the data stored.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted at: http://www.msofficeforums.com/word-v...name-also.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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