Save as syntax and range.select index syntax?
I'm trying to write some lines of codes that select a range in excel but the index to the range has a syntax error any suggestions? Also I'm trying to save a XML file as an xlsm file with file names from the concactenation of two file names stored in an array and is getting a similar error.any suggestions??
Range (Allfiles(index)).select 'Allfiles is an array containing the file names ' type error
Activeworkbooks.saveas "c:\Al开发者_开发问答lfiles(1):&:Allfiles (count).xlsm", fileformat=52 'error
When you get an "error", a useful "error message" will give you a hint as to what the problem is. By reading this message and acting upon it, you can debug your code step by step.
Activeworkbooks.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat = 52
' Variable not defined ^
The way to specify arguments in VBA is with :=
, not =
. Let's correct that and run it again...
Activeworkbooks.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat:=52
' ^ Variable not defined
It's called ActiveWorkbook
, not Activeworkbooks
. Let's correct that and run it once more...
ActiveWorkbook.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat:=52
' ^ The file could not be accessed.
I can't claim to know for sure what OS you're running, but given the C:\
, I'll assume some flavour of Windows. You may know that :
is an illegal character in paths in Windows?
Anyhow, I'm not sure where you're trying to save this file. My best guess:
ActiveWorkbook.SaveAs "C:\" & Allfiles(1) & Allfiles(UBound(Allfiles)) & ".xlsm", _
FileFormat:=52
As for you first line of code, Range (Allfiles(index)).Select
, I have no clue what you're trying to do there. You may want to read Excel-VBA's help file to learn what Range
does.
精彩评论