PDA

View Full Version : HELP- Vba to copy Word to Excel



jamesr1976
01-31-2014, 08:22 AM
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

westconn1
01-31-2014, 01:50 PM
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")

snb
02-01-2014, 05:54 AM
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