Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

Save errors - runtime '1004'

$
0
0

I have an issue runtime error 1004 with the below code, could anyone clarify for me what could be driving this?

Sub Excel1()

   Dim rngLoopRange As Range
   Dim wsSummary As Worksheet
   Dim rngDealers As Worksheet

   Set wsSummary = Sheets("PL")

   For Each rngLoopRange In Worksheets("AUX").Range("A1:A38")
      wsSummary.Range("C12").Value = rngLoopRange.Value

    Application.Run "TM1REFRESH"

    Dim wb As Workbook
    Set wb = Workbooks.Add
    ActiveWorkbook.SaveAs filename:=ThisWorkbook.Path & "\"& Range("C12").Value
    ws.Copy before = wb.Worksheets(1)


Next rngLoopRange

Set wsSummary = Nothing

    MsgBox "Complete!", vbInformation

End Sub

The above is now saving the file using the name I wanted, can you please advise now why it is giving me an

error '424'

on the sheet copying over. with the code line ws.Copy before = wb.Worksheets(1)

Sub Excel1()

   Dim rngLoopRange As Range
   Dim wsSummary As Worksheet
   Dim rngDealers As Worksheet

   Set wsSummary = Sheets("PL")

   For Each rngLoopRange In Worksheets("AUX").Range("A1:A38")
      wsSummary.Range("C12").Value = rngLoopRange.Value

    Application.Run "TM1REFRESH"

    Dim wb As Workbook
    Set wb = Workbooks.Add
    ActiveWorkbook.SaveAs filename:=ThisWorkbook.Path & "\"& wsSummary.Range("C12").Value
    ws.Copy before:=wb.Worksheets(1)
    wb.Close savechanges:=True


Next rngLoopRange

Set wsSummary = Nothing

    MsgBox "Complete!", vbInformation

End Sub

Viewing all articles
Browse latest Browse all 88868


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>