Problems with Creating/Executing Excel Macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Catbkr1
    New Member
    • Nov 2008
    • 1

    Problems with Creating/Executing Excel Macro

    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.
    Last edited by Frinavale; Jan 9 '09, 10:02 PM. Reason: Moved to Access Answers from Insights
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Hey there good buddy!

    Sorry, you probably needed this right away. Most of us are are spread out all over the world; time diffrence and all, hope you understand...

    That said, I am not skilled at Macros, but I reckon the Access forum may help you get an idea.

    How about giving them a try, see what pops up:-)

    In a bit!

    Comment

    Working...