VBA Macro not working I dont know why

EEEEE

New Member
Joined
Oct 23, 2015
Messages
14
Hi all,

I am not quite new to VBA in a practical sense.

I have been working on this macro today but I cant seem to get it to paste for some reason, It was intended to open hyperlinked documents from a excel file, within this document is a word table, from which I run a macro to copy the desired information, but when I come to putting this information back into the Excell sheet. It does not work. If I run the macro without the paste section and manually paste it - it works. See below:

Excel Macro
Code:
Option Explicit
Sub odoc()
Dim fpath As String
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
fpath = Application.ActiveCell.Value
objWord.Documents.Open (fpath)
objWord.Visible = True
objWord.Application.Run MacroName:="CopySAM"
objWord.Application.Quit
ActiveCell.Offset(0, 14).Select
ActiveSheet.Paste
End Sub

Word Macro
Code:
Sub CopySAM()
Dim tbl1 As Table
Set tbl1 = ActiveDocument.Tables(1)
tbl1.Cell(4, 2).Range.Copy
End Sub

Any input would be greatly appreciated.
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Typo on this line
Code:
ActiveShee.Paste
Your missing a t
 
Upvote 0
Hi

Thanks for the reply much appreciated, the actual syntax in VBA is without the error you mentioned and I get the below error, any ideas?

Run-time error'1004'

Paste Method of Worksheet class failed.
 
Last edited:
Upvote 0
Try swapping the the last 3 lines like this
Code:
ActiveCell.Offset(0, 14).Select
ActiveSheet.Paste
objWord.Application.Quit
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top