2016-04-07 24 views
0

私は複数のワークシートを実行して、ミーティングのデータを入力しています。私が実行しようとするたびに、私はメモリエラーと '1004'エラーを取得します。私はコーディングの初心者ですので、詳細を教えてください。助言がありますか?VBAランタイムエラー1004 "アプリケーション定義またはオブジェクト定義のエラー"

Sub PullData() 

    Application.ScreenUpdating = False 
    Application.EnableEvents = False 

    Sheets("Production").Select 

    Dim StartYear As String 
    Dim StartMonth As String 
    Dim StartDay As String 

    Dim EndYear As String 
    Dim EndMonth As String 
    Dim EndDay As String 

    Dim NextDay As String 
    Dim StartHour As String 
    Dim EndHour As String 

    StartYear = Year(Range("b2").Value) 
    StartMonth = Month(Range("b2").Value) 
    StartDay = Day(Range("b2").Value) 

    EndYear = Year(Range("b2").Value) 
    EndMonth = Month(Range("b2").Value) 
    EndDay = Day(Range("b2").Value) 

    NextDay = EndDay + 1 

    StartHour = Hour(Range("b3").Value) 
    EndHour = Hour(Range("b3").Value) 




    Sheets("PPA").Select 
    Cells.Select 
    Selection.ClearContents 
    With ActiveSheet.QueryTables.Add(Connection:="URL;https://fclmportal.amazon.com/ppa/inspect/node?nodeType=FC&warehouseId=ONT8&startDateDay=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&startDateWeek=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&startDateMonth=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&maxIntradayDays=1&spanType=Intraday&startDateIntraday=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&startHourIntraday=" & StartHour & "&startMinuteIntraday=0&endDateIntraday=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&endHourIntraday=" & EndHour & "&endMinuteIntraday=0", Destination:=Range("A1")) 

    Selection = 3 
    Formatting = None 
    PreFormattedTextToColumns = True 
    ConsecutiveDelimitersAsOne = True 
    SingleBlockTextImport = False 
    DisableDateRecognition = False 
    DisableRedirections = False 


    End With 

    Sheets("PPR").Select 
    Cells.Select 
    Selection.ClearContents 
    With ActiveSheet.QuryTables.Add(Connection:="URL;https://fclm-portal.amazon.com/reports/processPathRollup?reportFormat=HTML&warehouseId=ONT8&startDateDay=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&maxIntradayDays=1&spanType=Intraday&startDateIntraday=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&startHourIntraday=" & StartHour & "&startMinuteIntraday=0&endDateIntraday=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&endHourIntraday=" & EndHour & "&endMinuteIntraday=0&_adjustPlanHours=on&_hideEmptyLineItems=on&employmentType=AllEmployees", Destination:=Range("A1")) 

    Selection = 2 
    Formatting = None 
    PreFormattedTextToColumns = True 
    ConsecutiveDelimitersAsOne = True 
    SingleBlockTextImport = False 
    DisableDateRecognition = False 
    DisableRedirections = False 

     End With 


     Sheets("FR").Select 
     Cells.Select 
     Selection.ClearContents 
     With ActiveSheet.QueryTables.Add(Connection:="URL;https://fclm-portal.amazon.com/reports/functionRollup?warehouseId=ONT8&spanType=Intraday&startDate=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "T" & StartHour & ".000&endDate=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "T" & EndHour & ".000&reportFormat=HTML&processId=01003021", Destination:=Range("A1")) 

     Selection = Summary 
     Formatting = None 
     PreFormattedTextToColumns = True 
     ConsecutiveDelimitersAsOne = True 
     SingleBlockTextImport = False 
     DisableDateRecognition = False 
     DisableRedirections = False 

     End With 

     Sheets("PR").Select 
     Cells.Select 
     Selection.ClearContents 
     With ActiveSheet.QueryTables.Add(Connection:="URL;https://fclm-portal.amazon.com/reports/functionRollup?reportFormat=HTML&warehouseId=ONT8&processId=1003032&maxIntradayDays=1&spanType=Intraday&startDateIntraday=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&startHourIntraday=" & StartHour & "&startMinuteIntraday=0&endDateIntraday=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&endHourIntraday=" & EndHour & "&endMinuteIntraday=0", Destination:=Range("A1")) 

     Selection = Summary 
     Formatting = None 
     PreFormattedTextToColumns = True 
     ConsecutiveDelimitersAsOne = True 
     SingleBlockTextImport = False 
     DisableDateRecognition = False 
     DisableRedirections = False 

     End With 

     Sheets("PV").Select 
     Cells.Select 
     Selection.ClearContents 
     With ActiveSheet.QueryTables.Add(Connection:="URL;https://fclm-portal.amazon.com/reports/functionRollup?reportFormat=HTML&warehouseId=ONT8&processId=1003018&startDateDay=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&maxIntradayDays=1&spanType=Intraday&startDateIntraday=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&startHourIntraday=" & StartHour & "&startMinuteIntraday=0&endDateIntraday=" & StartYear & "%2F" & StartMonth & "%2F" & StartDay & "&endHourIntraday=" & EndHour & "&endMinuteIntraday=0", Destination:=Range("A1")) 

    Selection = Summary 
    Formatting = None 
    PreFormattedTextToColumns = True 
    ConsecutiveDelimitersAsOne = True 
    SingleBlockTextImport = False 
    DisableDateRecognition = False 
    DisableRedirections = False 

    End With 

    End Sub 
+0

エラーの原因は次のうちどれですか? – findwindow

+0

これは41行目の「Selection = 3」 – Treybo

+2

ああから始まります。 'selection'は予約語です。これを変数として使うことはできません。別の名前を選択してください。変数を宣言します。 – findwindow

答えて

0

With内部メソッド... End Withは、コードのかなりの数の行を修正する必要があるので、これは、確かにエラーがスローされます.を付加する必要があります。 Selectionはこれを修正しても機能しない可能性があります(私はExcelをテストしていません)。

また、Rangeを完全修飾すると便利です。一例としてthis answerを参照してください。これは何度も現れます。

関連する問題