Run-time error '1004' in Win10 not Win7

MichaelRSnow

Active Member
Joined
Aug 3, 2010
Messages
382
Hi

I get the following error on the below code (Run-time error '1004' Application-defined or object-defined error), which is very strange as when I run this on my windows 7 machine it runs fine but when I run it from my Windows 10 machine it falls over. Also if it step through the code manually with F8 on the Windows 10 machine it also works fine?

Any ideas? I'm stumped 🤞


VBA Code:
'paste output in destination format
ThisWorkbook.Worksheets(sheetName).PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
False, NoHTMLFormatting:=True
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,026
Office Version
  1. 2016
Platform
  1. Windows
Do both PCs have same Excel version?
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,993
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Can you post the 2 lines above the one you posted please. I suspect that you are coming out of copy mode before the paste.
 

MichaelRSnow

Active Member
Joined
Aug 3, 2010
Messages
382
Hey Mark858, yeah I think you are right as when I placed a MsgBox above the code to confirm the Scenario being pasted it stopped the error, this was the previous code below, what is the best solution to overcoming this? My MsgBox solution isn't the best idea


VBA Code:
'results page
ie.ExecWB 17, 0 '// SelectAll
ie.ExecWB 12, 2 '// Copy selection

'creates sheet and names it 'scenario x'
scenarioNumber = shtMacro.Range("B2").Value
sheetName = "Scenario" & scenarioNumber
Worksheets.Add().Name = sheetName
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,993
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile

ADVERTISEMENT

Try moving the Select/Copy below the Worksheets.Add
 
  • Like
Reactions: Zot

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,993
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
You're welcome.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,861
Messages
5,627,315
Members
416,239
Latest member
Counselor85027

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
Top