+ Reply to Thread
Results 1 to 2 of 2

Open a word document template through an excel vba (mac office 2011)

  1. #1
    Registered User
    Join Date
    10-27-2012
    Location
    Kelowna, England
    MS-Off Ver
    Excel 2011
    Posts
    4

    Unhappy Open a word document template through an excel vba (mac office 2011)

    Hi all,

    I have an excel document which i've been playing with and i need to be able to get a selection from the spreadsheet and special paste it as a picture into a new document created from my word template. I have a code that opens word but no document or anything opens it is just the standard new document page from word. Im new at vba coding so this code has been patched together from sources ive found all over the shop.
    Thank you in advance!!

    Sub Openspecificword()

    Range("A1:F26").Select
    Selection.Copy
    Dim word As Object
    Dim doc As Object
    On Error Resume Next
    Set word = GetObject(, "word.application") 'gives error 429 if Word is not open
    If Err = 429 Then
    Set word = CreateObject("word.application")
    'creates a Word application
    Err.Clear
    End If
    word.Visible = True
    Set doc = word.document.Add("/Volumes/Mac HDD/Me/Documents/Invoice.dotx")

    End Sub

  2. #2
    Registered User
    Join Date
    10-27-2012
    Location
    Kelowna, England
    MS-Off Ver
    Excel 2011
    Posts
    4

    Re: Open a word document template through an excel vba (mac office 2011)

    I found this which works perfectly on excel 2003 but i cannot get it to work on my excel 2011.
    Sub Copy_MetaFile_to_MSWord_Template()
    '1) Copy cells ("A1:G30")
    '2) Open a specific word template "template 123.dot"
    '3) Paste special picture (metafile)
    '4) Save that word doc - naming the file the text found in 3 of the cells of sheet2 (a1, a2 & a3), into a specific folder ("...desktop\my folder")

    Dim WrdApp As Object, WrdDoc As Object
    Dim strMyFolderPath As String, strWrdFileName As String

    Set WrdApp = CreateObject("Word.Application")
    Set WrdDoc = WrdApp.Documents.Open("C:\Temp\template 123.dot")
    'WrdApp.Visible = True

    ThisWorkbook.ActiveSheet.Range("A1:G30").Copy
    With WrdDoc.Range
    .Collapse Direction:=0 'End of document
    .InsertParagraphAfter 'Insert paragraph
    .Collapse Direction:=0 'End of document
    .PasteSpecial False, False, 0, False, 9 'Paste as Enhanced Metafile
    End With

    strMyFolderPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\My Folder\"
    With ThisWorkbook.ActiveSheet
    strWrdFileName = .Range("A1").Value & .Range("A2").Value & .Range("A3").Value & ".doc"
    End With
    WrdDoc.SaveAs strMyFolderPath & strWrdFileName
    WrdDoc.Close
    WrdApp.Quit

    Application.CutCopyMode = True
    MsgBox "Range A1:G30 copied to Word Doc " & vbLf & vbLf & _
    strWrdFileName, vbInformation, "Range Copied to Word"

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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