+ Reply to Thread
Results 1 to 4 of 4

Help with code: amend file path

  1. #1
    Registered User
    Join Date
    02-11-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    4

    Help with code: amend file path

    Hi,

    I have the following code and i would like to know how to amend it so the user can choose a specific word file as opposed to the embedded "pushmerge.dot"

    Option Explicit

    Sub BCMerge()
    Dim pappWord As Object
    Dim docWord As Object
    Dim wb As Excel.Workbook
    Dim xlName As Excel.Name
    Dim TodayDate As String
    Dim Path As String

    Set wb = ActiveWorkbook
    TodayDate = Format(Date, "mmmm d, yyyy")
    Path = wb.Path & "\pushmerge.dot"

    On Error GoTo ErrorHandler

    'Create a new Word Session
    Set pappWord = CreateObject("Word.Application")

    On Error GoTo ErrorHandler

    'Open document in word
    Set docWord = pappWord.Documents.Add(Path)

    'Loop through names in the activeworkbook
    For Each xlName In wb.Names
    'if xlName's name is existing in document then put the value in place of the bookmark
    If docWord.Bookmarks.Exists(xlName.Name) Then
    docWord.Bookmarks(xlName.Name).Range.Text = Range(xlName.Value)
    End If
    Next xlName

    'Activate word and display document
    With pappWord
    .Visible = True
    .ActiveWindow.WindowState = 0
    .Activate
    End With

    'Release the Word object to save memory and exit macro
    ErrorExit:
    Set pappWord = Nothing
    Exit Sub

    'Error Handling routine
    ErrorHandler:
    If Err Then
    MsgBox "Error No: " & Err.Number & "; There is a problem"
    If Not pappWord Is Nothing Then
    pappWord.Quit False
    End If
    Resume ErrorExit
    End If
    End Sub

  2. #2
    Forum Contributor
    Join Date
    01-13-2013
    Location
    Oklahoma
    MS-Off Ver
    Office 2007 / Office 2010
    Posts
    123

    Re: Help with code: amend file path

    You can use this to allow the user to pick the document.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-11-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Help with code: amend file path

    sorry im a bit of an amatuer, which part of the code do i replace with your suggested code?

  4. #4
    Forum Contributor
    Join Date
    01-13-2013
    Location
    Oklahoma
    MS-Off Ver
    Office 2007 / Office 2010
    Posts
    123

    Re: Help with code: amend file path

    Replace:
    Please Login or Register  to view this content.
    with this:
    Please Login or Register  to view this content.
    Just be sure to include the function GetPath in a module.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1