Hello, I'm currently working through Excel 2007 Programming VBA for Dummies book, and I'm having trouble with what I want excel to do.
Using the code below, I can get the activesheet name changed but it will only copy to after the FIRST sheet in another workbook.
Am I missing something here? Are there any attributes I should check in the workbook i'm copying to/from?
Thanks for your helpSub Macro1() ' ' Macro1 Macro ' ' Keyboard Shortcut: Ctrl+Shift+D ' ' Every macro should have this of course... Application.ScreenUpdating = False Application.Calculation = xlCalculationManual ' Start main code ActiveSheet.Name = Range("H13").Value ActiveSheet.Copy After:=Workbooks("APRIL 10.xls").Sheets(Sheets.Count) ' End main code Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub
btw: This site looks awesome!
Hello Giant_Cheeseman,
Welcome to the Forum!
To make your code easier to read and more flexible, you can assign object variables to the workbooks.
Sub Macro1() ' ' Macro1 Macro ' ' Keyboard Shortcut: Ctrl+Shift+D ' Dim DstWkb As Workbook Set DstWks = Workbooks("APRIL 10.xls") ' Every macro should have this of course... Application.ScreenUpdating = False Application.Calculation = xlCalculationManual ' Start main code ActiveSheet.Name = Range("H13").Value ActiveSheet.Copy After:=DstWkb.Sheets(DstWkb.Sheets.Count) ' End main code Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hello Giant_Cheeseman,
That's my fault due to a typo. I corrected the typo in this code.
Sub Macro1() ' ' Macro1 Macro ' ' Keyboard Shortcut: Ctrl+Shift+D ' Dim DstWkb As Workbook Set DstWkb = Workbooks("APRIL 10.xls") ' Every macro should have this of course... Application.ScreenUpdating = False Application.Calculation = xlCalculationManual ' Start main code ActiveSheet.Name = Range("H13").Value ActiveSheet.Copy After:=DstWkb.Sheets(DstWkb.Sheets.Count) ' End main code Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Ah, yes that worked. However only after I realised my macro key stopped working. I have reset it in macro options, and the code worked.
Thanks!
Just a quick question, could this code have an attachment where in the same process, it could save the workbook as the value defined (H13)?
Or potentially save the sheet as a workbook with the sheet name (might be easier)?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks