+ Reply to Thread
Results 1 to 3 of 3

excel to word macro

  1. #1
    Registered User
    Join Date
    01-04-2016
    Location
    Whitewater, WI
    MS-Off Ver
    Microsoft Office 2010
    Posts
    5

    excel to word macro

    I am trying to create a macro to take a range of cells from excel, open a word document and paste the cells as a linked file. This is going to be used in our field service report template. This is the code I have thus far but keep getting a Compile error: Expected End With. Not to sure where to put the end with as I am just learning macro's on the fly. Any help would be appreciated.

    Sub Macro1blam()


    Range("A1:J46").Select
    Application.CutCopyMode = False
    Selection.Copy
    Dim objWord As Object

    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True



    objWord.Documents.Open "C:\Users\PAC00735\Desktop\Working copy tech paperwork\doc2.docx"

    With objWord_
    With Selection.PageSetup
    .LineNumbering.Active = False
    .Orientation = wdOrientPortrait
    .TopMargin = InchesToPoints(0.5)
    .BottomMargin = InchesToPoints(0.5)
    .LeftMargin = InchesToPoints(0.5)
    .RightMargin = InchesToPoints(0.5)
    .Gutter = InchesToPoints(0)
    .HeaderDistance = InchesToPoints(0.5)
    .FooterDistance = InchesToPoints(0.5)
    .PageWidth = InchesToPoints(8.5)
    .PageHeight = InchesToPoints(11)
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    .SectionStart = wdSectionNewPage
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = wdAlignVerticalTop
    .SuppressEndnotes = False
    .MirrorMargins = False
    .TwoPagesOnOne = False
    .BookFoldPrinting = False
    .BookFoldRevPrinting = False
    .BookFoldPrintingSheets = 1
    .GutterPos = wdGutterPosLeft

    End With

    Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
    wdInLine, DisplayAsIcon:=False

    End Sub

  2. #2
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: excel to word macro

    delete me

    #
    #
    #
    #
    #
    #
    Frob first, tweak later

  3. #3
    Registered User
    Join Date
    01-04-2016
    Location
    Whitewater, WI
    MS-Off Ver
    Microsoft Office 2010
    Posts
    5

    Re: excel to word macro

    Well, the code doesn't work. Anyone know what I have to write into code to get it to work. I was able achieve the compile error thanks to Neil. This is the other code I am working with.

    Sub CopyChartToWordDocument()
    Dim wdApp As Word.Application
    'Copy embedded array
    ThisWorkbook.Sheets(3).Range("A1:J46").Copy
    'Establish link to Word
    Set wdApp = New Word.Application
    wdApp.Visible = True
    With wdApp
    'open Word Document
    Documents.Open Filename:="C:\Users\????????\Desktop\Working copy tech paperwork\Field_Service_Report_Template1.dotm"
    With wdApp.Selection
    'Go to end of document and insert paragraph
    .TypeParagraph
    .PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:=wdInLine, DisplayAsIcon:=False

    End With
    End With
    'Release object variable
    Set wdApp = Nothing
    End Sub
    Last edited by ryan2984; 01-04-2016 at 05:46 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel to Word macro doesn't work on Word 2013 if sheet is hidden (works fine on 2010)
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2015, 04:37 AM
  2. Convert Word Table Macro to excel macro
    By vel90 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2015, 01:20 PM
  3. error when running MS Word macro commands in Excel macro
    By bsapaka in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2014, 01:30 PM
  4. [SOLVED] Excel macro- Find replace an itallic font word with a regular word?
    By thisisaboutwork in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2013, 01:48 PM
  5. Need help with Excel-to-Word find and replace macro based on word filename
    By EnterTheSerpent in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2013, 12:48 PM
  6. Replies: 3
    Last Post: 07-06-2006, 02:45 PM
  7. WORD-DELIMITED string vba macro for excel/word
    By jackal2k6 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2005, 12:35 PM

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