Consulting

Results 1 to 1 of 1

Thread: Runtime Error 1004

  1. #1

    Runtime Error 1004

    I need some assistance with this error. I cannot figure out why it is not working correctly as other macros I use setup similarly work just fine. I receive the runtime error where the code is bolded. Trying to take the data pulled from the one sheet, copy it, and place it in another.

    Edit by Mod Error at "<<<<<<<<<<<<<<<"

    Private Sub CommandButton1_Click()
    
    'Establish connection to SAP
    Dim App, Connection, session As Object
    Set SapGuiAuto = GetObject("SAPGUI")
    Set App = SapGuiAuto.getscriptingEngine
    Set Connection = App.Children(0)
    Set session = Connection.Children(0)
    
    'If MsgBox("Are yellow date boxes updated? ", vbYesNo) = vbNo Then Exit Sub
    'If MsgBox("Are all close transactions complete? ", vbYesNo) = vbNo Then Exit Sub
    
    'Clear Previous Data
        Sheets("Data_Input").Select
        Sheets("Data_Input").Cells.ClearContents
    
    'Data_Input
    session.findById("wnd[0]/tbar[0]/okcd").Text = "s_alr_87012052"
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/btn[0]").press
    session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssub/1/2/tblSAPLALDBSINGLE/ctxt[1,0]").Text = "5101"
    session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssub/1/2/tblSAPLALDBSINGLE/ctxt[1,1]").Text = "3751"
    session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssub/1/2/tblSAPLALDBSINGLE/ctxt[1,1]").SetFocus
    session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssub/1/2/tblSAPLALDBSINGLE/ctxt[1,1]").caretPosition = 4
    session.findById("wnd[1]/tbar[0]/btn[8]").press
    session.findById("wnd[0]/usr/rad[0]").Select
    session.findById("wnd[0]/usr/ctxt[13]").Text = "30"
    session.findById("wnd[0]/usr/ctxt[15]").Text = "z_retirement"
    session.findById("wnd[0]/usr/ctxt[16]").Text = Worksheets("Input Page").Range("D3").Text
    session.findById("wnd[0]/usr/ctxt[17]").Text = Worksheets("Input Page").Range("D4").Text
    session.findById("wnd[0]/usr/ctxt[17]").SetFocus
    session.findById("wnd[0]/usr/ctxt[17]").caretPosition = 10
    session.findById("wnd[0]").sendVKey 8
    
    'click the export to file button
    session.findById("wnd[0]/tbar[1]/btn[9]").press
    'choose the export format
    session.findById("wnd[1]/usr/sub/2/sub/2/1/rad[1,0]").Select
    session.findById("wnd[1]/usr/sub/2/sub/2/1/rad[1,0]").SetFocus
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    'choose the export file name
    session.findById("wnd[1]/usr/ctxt[0]").Text = "\\us-filesp02\Teams2\FIXEDASSETS\FixedAssetReports\AssetRetirements\"
    session.findById("wnd[1]/usr/ctxt[1]").Text = "assetretirements.xls"
    session.findById("wnd[1]/usr/ctxt[1]").caretPosition = 20
    session.findById("wnd[1]/tbar[0]/btn[11]").press
    
    'Once you open this workbook that has the exported information you can start using the Excel Macro Record
    Workbooks.Open ("\\us-filesp02\Teams2\FIXEDASSETS\FixedAssetReports\AssetRetirements\assetretirements.xls")
        
    'Copy the information that was exported from excel
        Windows("assetretirements.xls").Activate
        Range("A1").Select '<<<<<<<<<<<<<<<
        Columns("A:Q").Select
        Selection.Copy
        'Below line needs to be updated to correct file name
        Windows("Asset_Retirements.xlsm").Activate
        Sheets("Data_Input").Select
        Range("A1").Select
        ActiveSheet.Paste
        Columns("A:N").Select
        Columns("A:N").EntireColumn.AutoFit
        Range("A1").Select
        'Below line needs to be updated to correct file name
        Windows("assetretirements.xls").Activate
        Range("A1").Select
        Application.CutCopyMode = False
        ActiveCell.FormulaR1C1 = " "
        Range("A2").Select
        Selection.Copy
        ActiveWorkbook.Close (SaveChanges = False)
        Sheets("Input Page").Select
        Range("A2").Select
        ActiveWorkbook.Save
       
    End Sub
    Last edited by SamT; 04-08-2016 at 07:48 AM. Reason: Added CODE Tags with Editor's # icon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •