Consulting

Results 1 to 3 of 3

Thread: HELP- Vba to copy Word to Excel

  1. #1

    HELP- Vba to copy Word to Excel

    I have the folloing code to copy the full open word documnent and paste into the next available line in my excel sheet.
    Works perfectly on my machine, but when others users try and run it stops on the 3rd line of the code:

    any ideas? or a simpler way to do this?

    Sub Copywordpastecollation()
    Dim n As Integer, z As Boolean
    With ThisWorkbook.VBProject.References
    For n = 1 To .Count
    If InStr(.Item(n).Description, "Microsoft Word") Then GoTo 1
    Next n
    .AddFromGuid "{00020905-0000-0000-C000-000000000046}", 1, 0
    z = True
    1: End With
    HitIt (z)
    End Sub
    Private Sub HitIt(z As Boolean)
    Dim y As OLEObject, n As Integer
    Application.ScreenUpdating = False
    Documents(1).Content.Copy
    Sheets(1).[a1].PasteSpecial xlValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    Windows("2014 Wave 1 draft.xlsm").Activate
    Sheets("Paste From Word").Select
    Range("J2:J170").Select
    Selection.Copy
    Sheets("Sheet1").Select
    Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=True
    Sheets("paste from word").Select
    Columns("A:E").Select
    Selection.ClearContents

    If z = True Then
    With ThisWorkbook.VBProject.References
    For n = 1 To .Count
    If InStr(.Item(n).Description, "Word") Then
    .Remove .Item(n)
    Exit For


    End If
    Next n
    End With



    End If
    End Sub

  2. #2
    if they are using a different version of word, then a different guid

    no need for that anyway if you use late binding like
    set objword = createobject("word.application")

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    sub M_snb()
       getobject(,"Word.application").documents(1).content.copy
       Workbooks("2014 Wave 1 draft.xlsm").Sheets("Paste From Word").Paste Workbooks("2014 Wave 1 draft.xlsm").Sheets("Paste From Word").cells(1,1)
    End sub

Posting Permissions

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