-
Oct 19th, 2020, 11:39 AM
#1
Thread Starter
New Member
Cant copy/paste from workbook when using shortcut/hot key
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???
-
Oct 19th, 2020, 02:25 PM
#2
Thread Starter
New Member
Re: Cant copy/paste from workbook when using shortcut/hot key
-
Oct 21st, 2020, 02:24 AM
#3
Re: Cant copy/paste from workbook when using shortcut/hot key
i pasted your code into a procedure and assigned a hotkey ctrl+m, the code worked as expected either using the hot key or from the ide
did you try specifying the full path to the file?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|