D
Dan R.
I'm trying to open a new WB, copy & paste values from the ActiveSheet
to the WB, then close & save the WB on the desktop. When I run this I
get a run-time error '1004': "Copy method of Range class failed" and
my copy/paste line is highlighted.
Sub Test()
Dim csFILENAME As String
Dim wsh As Object
Dim xlApp As Application
Dim xlBook As Workbook
Dim xlSheet As Worksheet
Dim ws As Excel.Worksheet
Set wsh = CreateObject("wscript.shell")
csFILENAME = wsh.SpecialFolders.Item("Desktop")
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add( Template:="Workbook")
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Visible = True
Set ws = ActiveSheet
ws.Range("B3").Copy xlSheet.Range("A1") <<< This is highlighted
xlBook.SaveAs (csFILENAME & "\" & "Test " & _
Format(Now(), "mm-dd-yy") & ".xls")
xlBook.Close
Set xlApp = Nothing
End Sub
Thanks,
-- Dan
to the WB, then close & save the WB on the desktop. When I run this I
get a run-time error '1004': "Copy method of Range class failed" and
my copy/paste line is highlighted.
Sub Test()
Dim csFILENAME As String
Dim wsh As Object
Dim xlApp As Application
Dim xlBook As Workbook
Dim xlSheet As Worksheet
Dim ws As Excel.Worksheet
Set wsh = CreateObject("wscript.shell")
csFILENAME = wsh.SpecialFolders.Item("Desktop")
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add( Template:="Workbook")
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Visible = True
Set ws = ActiveSheet
ws.Range("B3").Copy xlSheet.Range("A1") <<< This is highlighted
xlBook.SaveAs (csFILENAME & "\" & "Test " & _
Format(Now(), "mm-dd-yy") & ".xls")
xlBook.Close
Set xlApp = Nothing
End Sub
Thanks,
-- Dan