J
J. Henke
Hello, all.
When I launch Excel 2000 with an Auto_Open macro in my PERSONAL.XLS
workbook, I receive a "Run-time error '1004': Method 'Range' of object
'_Global' failed."
It's particularly confusing because when I debug, I do not see any
problems with the code (it breaks on a line with the code:
"Range("AE1").Select").
If I am to run the macro manually, it executes properly. However,
this Auto_Open procedure is giving me (and apparently Excel) fits.
Any suggestions would be wonderful.
Thank you,
J. Henke
P.S. Below is the macro's code:
Sub Auto_Open()
'Select the first "signature" cell
Range("AE1").Select
'Verify whether or not this is a spreadsheet to convert
If ActiveCell.Value = "Commission %" Then
'Select column A
Columns("A:A").Select
'Insert a new column, and shift the other columns to the right
Selection.Insert Shift:=xlToRight
'Select the first row in the spreadsheet
Rows("1:1").Select
'Delete the header row and shift up
Selection.Delete Shift:=xlUp
'Select cell A1
Range("A1").Select
'Declare a variable to store the number of rows in the active
worksheet
Dim numRowsInSheet As Integer
'Count the number of rows in the active worksheet and store
them in a variable
numRowsInSheet = ActiveSheet.UsedRange.Rows.Count
'Declare a new string
Dim myCellVal As String
'Store the new range (with the variable number of rows) in the
string
myCellVal = "A1:A" & numRowsInSheet
'Insert 1 in cell A1 for the first RecordID
ActiveCell.FormulaR1C1 = "1"
Range("A1").Select
'Use Excel's AutoFill function to fill the whole range of
cells with 1's for the RecordID
Selection.AutoFill Destination:=Range(myCellVal),
Type:=xlFillDefault
'Range("A1:A6").Select
'Initialize a general property in columns 1 through 42 to
ensure that 42 columns get
'some sort of tab delimiter
Range("A1:AP1").Select
Selection.Font.Italic = True
Selection.Font.Italic = False
'Change to the directory in which to save the project
ChDir "C:\My Documents"
ActiveWorkbook.SaveAs Filename:="C:\My
Documents\myFlatFile.txt" _
, FileFormat:=xlText, CreateBackup:=False
Else
MsgBox "Sorry chum, this isn't an acceptable spreadsheet!",
vbInformation, "Sorry!"
End If
'
End Sub
When I launch Excel 2000 with an Auto_Open macro in my PERSONAL.XLS
workbook, I receive a "Run-time error '1004': Method 'Range' of object
'_Global' failed."
It's particularly confusing because when I debug, I do not see any
problems with the code (it breaks on a line with the code:
"Range("AE1").Select").
If I am to run the macro manually, it executes properly. However,
this Auto_Open procedure is giving me (and apparently Excel) fits.
Any suggestions would be wonderful.
Thank you,
J. Henke
P.S. Below is the macro's code:
Sub Auto_Open()
'Select the first "signature" cell
Range("AE1").Select
'Verify whether or not this is a spreadsheet to convert
If ActiveCell.Value = "Commission %" Then
'Select column A
Columns("A:A").Select
'Insert a new column, and shift the other columns to the right
Selection.Insert Shift:=xlToRight
'Select the first row in the spreadsheet
Rows("1:1").Select
'Delete the header row and shift up
Selection.Delete Shift:=xlUp
'Select cell A1
Range("A1").Select
'Declare a variable to store the number of rows in the active
worksheet
Dim numRowsInSheet As Integer
'Count the number of rows in the active worksheet and store
them in a variable
numRowsInSheet = ActiveSheet.UsedRange.Rows.Count
'Declare a new string
Dim myCellVal As String
'Store the new range (with the variable number of rows) in the
string
myCellVal = "A1:A" & numRowsInSheet
'Insert 1 in cell A1 for the first RecordID
ActiveCell.FormulaR1C1 = "1"
Range("A1").Select
'Use Excel's AutoFill function to fill the whole range of
cells with 1's for the RecordID
Selection.AutoFill Destination:=Range(myCellVal),
Type:=xlFillDefault
'Range("A1:A6").Select
'Initialize a general property in columns 1 through 42 to
ensure that 42 columns get
'some sort of tab delimiter
Range("A1:AP1").Select
Selection.Font.Italic = True
Selection.Font.Italic = False
'Change to the directory in which to save the project
ChDir "C:\My Documents"
ActiveWorkbook.SaveAs Filename:="C:\My
Documents\myFlatFile.txt" _
, FileFormat:=xlText, CreateBackup:=False
Else
MsgBox "Sorry chum, this isn't an acceptable spreadsheet!",
vbInformation, "Sorry!"
End If
'
End Sub