|
-
Oct 27th, 2004, 04:04 PM
#1
Thread Starter
Lively Member
*SOLVED* subscript out of range error
I have made a macro for copy and paste into a new file.
Copied it into vba editor into my code.
Worked fine, but not anymore.
It makes a new file but as soon as it wants to go back to
"Windows("file.xls").Activate"
"it gives a suscripts out of range" error
I have checked for the value of "strBestandMap"
and "strBestand" both are not changed and are fine.
This is my code:
VB Code:
Workbooks.Add
ChDir strBestandMap
ActiveWorkbook.SaveAs Filename:=strBestand
Windows("file.xls").Activate
Sheets("resultaten").Select
Cells.Select
Selection.Copy
Windows("" & strBestandNaam & "").Activate
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
Thanks in advance,
Brian
Last edited by brianbaart; Nov 1st, 2004 at 11:04 AM.
If Not Now Then When
If Not Here Then Where
-
Oct 27th, 2004, 11:31 PM
#2
When you do a SaveAs it will change the file to the new name
and the original one is closed. Use the .SaveCopyAs instead.
VB Code:
ActiveWorkbook.SaveCopyAs Filename:=strBestand
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 1st, 2004, 10:51 AM
#3
Thread Starter
Lively Member
Sorry it has taken so long but NO
Converting SaveAs to SaveCopyAs has not helped at all.
VB Code:
Workbooks.Add
ChDir strBestandMap
ActiveWorkbook.SaveAs Filename:=strBestand
Workbooks("file.xls").Activate
Sheets("resultaten").Select
Cells.Select
Selection.Copy
Workbooks("" & strBestandNaam & "").Activate
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
The programs stops at:
Workbooks("Royaltys.xls").Activate
And gives a "Subscript out of range" error
It has worked before I have made some changes to the code somewhere else in the program (nothing to do with this)
and now it doesn't work.
HELP SOMEBODY HELP,
Thanks in advance,
Brian
If Not Now Then When
If Not Here Then Where
-
Nov 1st, 2004, 11:03 AM
#4
Thread Starter
Lively Member
Solved It
Thanks for reading it,
But I have made a new macro.
Sheets("resultaten").Select
Cells.Select
Selection.Copy
Workbooks.Add
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Application.CutCopyMode = False
ActiveWorkbook.SaveAs Filename:=strBestand
ActiveWindow.Close
Range("A1").Select
Sheets("start").Select
Range("A1").Select
It no longer gives the error
Don't know why but it doesn't.
If Not Now Then When
If Not Here Then Where
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
|