Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15840

MsOf07 Cant copy/paste from workbook when using shortcut/hot key

$
0
0
I have encountered a very strange problem. I have some code that opens a second workbook, copies a sheet from the second workbook into the first workbook (where the VBA is), then closes the second workbook. It works fine if I run it from the code window, or by using View Macros. However, if I try to run it using an assigned Shortcut/Hot Key (CTRL+J or CTRK+M), it will open the second workbook then hang. It won't do the copy or close the workbook. I have tried 4 different ways of doing the copy/paste (cells.select, selection.copy, ActiveSheet.copy, and the following code). All of them behave the same way - they work but not with the shortcut/hot key

SourceFile = “Filename.csv”

Set SourceBook = Workbooks.Open(SourceFile)
SourceBook.Sheets(1).Copy After:=ThisWorkbook.Sheets(1)
SourceBook.Close SaveChanges:=False

Why is there a difference when running this from a shortcut/hot key???

Viewing all articles
Browse latest Browse all 15840

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>