Run time error - Microsoft Excel cannot paste the data

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
608
Office Version
  1. 365
Platform
  1. Windows
Hello,
This is a bit baffling because the code has been working fine for most users and one person who has a new computer is giving me the headache.
The summary of this macro is it opens a PDF, copies and pastes it to sheet. I repeat this process for several PDF reports, open, copy, paste, close. Works fine for most people but for one person, it gets a runtime error:

VBA Code:
.Range("A" & LastRow).PasteSpecial Paste:=xlPastevalue

It works fine the first run but when used for the second run, we get a runtime error. When I hit debug and F8 through the code, it continues correctly which make me think it doesn’t know where to paste the data.
I also tried .pastespecial format:=”Text” and it did the same thing, worked on the first pass, error on the second.

Here is a snippet of the code:

VBA Code:
Set myworksheet = ActiveWorkbook.Worksheets("Interim")
Call Shell(Pathname:=shellpathname, Windowstyle:=vbNormalFocus)

‘Copy open PDF
Application.Wait Now + TimeValue("0:00:03")

SendKeys "^a"
SendKeys "^c"

'Unhide Sheet
Worksheets("Interim").Visible = True
Application.Wait Now + TimeValue("0:00:03")

Call Shell("TaskKill /F /IM Acrobat.exe", vbHide)

‘Paste PDF in next available row
With myworksheet
    .Range("A1") = "A"
    LastRow = myworksheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
    .Range("A" & LastRow).PasteSpecial Paste:=xlPastevalue
End With

Any help is greatly appreciated
 
Another way to paste:

Rich (BB code):
  Set myworksheet = ActiveWorkbook.Worksheets("Interim")
  'Unhide Sheet
  myworksheet.Visible = True
  myworksheet.Select
  LastRow = myworksheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
  myworksheet.Range("A" & LastRow).Select
  
  'Copy open PDF
  Call Shell(Pathname:=shellpathname, Windowstyle:=vbNormalFocus)
  Application.Wait Now + TimeValue("0:00:03")
  SendKeys "^a", True
  Application.Wait Now + TimeValue("0:00:01")
  SendKeys "^c", True
  Application.Wait Now + TimeValue("0:00:03")

  'Paste PDF in next available row
  ActiveSheet.Paste
  
  'Close PDF
  Call Shell("TaskKill /F /IM Acrobat.exe", vbHide)
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
:( Works fine on my machine, not on my co-workers, same error message. Its really baffling.
 
Upvote 0
Difficult to pin point the issue. Wondering if has something to do with his version of Office.
 
Upvote 0
Maybe you should use another method to import the information from PDF to excel:



 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

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