I have to automatically create some Excel Spreadsheets based on automatically generated .CSV files that are produced overnight. Each .CSV has several columns that need to be deleted. The same columns (both in location and name) are deleted each time. The macro checks for Column Headers/Names and if the value isn't equal to one of 8 specifc values, I want to delete the column. I am attempting to create a Macro that executes automatically when a file is opened in Excel. I have found the Workbook_Open area in the VB Editor within Excel and have created a Macro that will execute when a file is opened. The macro will run successfully standalone outside of the Workbook_Open function. Whenever I add the macro to the Workbook_Open I receive a very generic error: Run-time error '1004' Method "Range" of Object'_Global Failed.
Here is the way I am executing the code:
ThisWorkbook has
Private Sub Workbook_Open()
FaxFormat
Here is the FaxFormat Macro
Sub FaxFormat()
Target1=OWNER_I D
Target2=FAXDIDN UM
Target3=REMOTEI D
Target4=SNED_TI ME
Target5=FAX_STA TUS
Target6=NUMPAGE S
Target7FAXDATE
Target8=FAXTIME
ActiveSheet.Ran ge("A1").Selec t THIS IS THE ROW WITH THE ERROR
Do Until ActiveCell=""
If ActiveCell.Valu e<>Target1 and ActiveCell.Valu e<>Target2 and ActiveCell.Valu e<>Target3 and ActiveCell.Valu e<>Target4 and ActiveCell.Valu e<>Target5 and ActiveCell.Valu e<>Target6 and ActiveCell.Valu e<>Target7 and ActiveCell.Valu e<>Target8 Then
Active.Cell.Ent ireColumn.Delet e
Else
ActiveCell.Offs et(0,1).Activat e
End If
Loop
The rest of the macro sorts and sizes columns, save the file and closes the file.
I am confused as the macro runs fine in standalone mode. It only errors when attempting to Auto Launch it upon opening of a file.
Thanks for any assistance.
Here is the way I am executing the code:
ThisWorkbook has
Private Sub Workbook_Open()
FaxFormat
Here is the FaxFormat Macro
Sub FaxFormat()
Target1=OWNER_I D
Target2=FAXDIDN UM
Target3=REMOTEI D
Target4=SNED_TI ME
Target5=FAX_STA TUS
Target6=NUMPAGE S
Target7FAXDATE
Target8=FAXTIME
ActiveSheet.Ran ge("A1").Selec t THIS IS THE ROW WITH THE ERROR
Do Until ActiveCell=""
If ActiveCell.Valu e<>Target1 and ActiveCell.Valu e<>Target2 and ActiveCell.Valu e<>Target3 and ActiveCell.Valu e<>Target4 and ActiveCell.Valu e<>Target5 and ActiveCell.Valu e<>Target6 and ActiveCell.Valu e<>Target7 and ActiveCell.Valu e<>Target8 Then
Active.Cell.Ent ireColumn.Delet e
Else
ActiveCell.Offs et(0,1).Activat e
End If
Loop
The rest of the macro sorts and sizes columns, save the file and closes the file.
I am confused as the macro runs fine in standalone mode. It only errors when attempting to Auto Launch it upon opening of a file.
Thanks for any assistance.
Comment