Consulting

Results 1 to 3 of 3

Thread: Save As?

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Save As?

    I have the code below to use excel to open a word document, what i need to figure out is how to do a save as instead of resaving the original document

    Any Help Much appreciated

    Gibbo

    Option Explicit
    
    Sub openWordPlease()
    ' dont forget to set a ref to word object library
        Dim wordApp As Object
        Dim wordFile As Object
        Dim myFile As String
        Dim Rename As String
        myFile = ThisWorkbook.Path & "\Test.doc"
        Rename = "Test" & Now() & ". Doc"
        Set wordApp = CreateObject("Word.Application")
        wordApp.Visible = True
        Set wordFile = wordApp.Documents.Open(myFile)
    On Error GoTo 0
        If wordFile Is Nothing Then
            MsgBox "File is not found!", vbInformation, "ERROR"
            GoTo quickEnd
        End If
        With wordFile
            .Range.Text = Range("A1").Value
            .SaveAs ThisWorkbook.Path & Rename
        End With
        'wordApp.Quit
    quickEnd:
        Set wordFile = Nothing
        Set wordApp = Nothing
    End Sub


  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    What problem do you actually have?

    That code looks OK to me.

  3. #3
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Thanks for your interest Norie

    The problem was to do with the date format not being compatible (the / part)

    Rename = "Test" & Now() & ". Doc"
    This thread wasnt working earlier so i posted another one

    http://www.vbaexpress.com/forum/showthread.php?t=1953

    This is solved there and i ve posted the working code if you wanna have a look

    Cheers

    Gibbo

Posting Permissions

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