Closing a workbook after Copy and before Paste

adambensaid

New Member
Joined
Feb 22, 2011
Messages
5
Hi,
I have a workbook (wb1) that has code to open a different workbook (wb2), copy the content of the csv file within wb2, close wb2, and paste the content to one of the sheets (Sheet1) in wb1.
The issue that I am having is that when wb2 is being closed, I receive the dreaded clipboard message. Since the paste command is after the close command, I cannot empty the clipboard until I paste the contents.
Code:
Application.CutCopyMode = False
Also, the Application.EnableEvents = False does not seem to help. Below is a snippet of the code. Unfortunately, I cannot pull the contents from a closed workbook (that I know) since the path can't be hard-coded. I would like the macro to run without prompting the user for anything. Can I:

  1. Somehow suppress the clipboard message
  2. Paste the contents in wb1, empty the clipboard, then close wb2 (How?)
  3. Other suggestions

Code:
    Range("A2:H2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy

ActiveWindow.Close savechanges:=False
Application.EnableEvents = False
ThisWorkbook.Activate
    Sheets("Sheet1").Activate
    Range("A2").Select
    ActiveSheet.Paste
Application.EnableEvents = True
Let me know if you need additional code. Thanks for your help.
Adam
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try replacing that with

Code:
Range("A2:H2").Select
Range(Selection, Selection.End(xlDown)).Copy Destination:=ThisWorkbook.Sheets("Sheet1").Range("A2")
ActiveWindow.Close savechanges:=False
Application.CutCopyMode = False
 
Upvote 0

Forum statistics

Threads
1,224,540
Messages
6,179,417
Members
452,912
Latest member
alicemil

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