Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Runtime Error 1004 - File could not be accessed

Hi there, i am getting a runtime error 1004...that the file could not be
accessed. The code it below, and the line in question is:

sbFile.SaveAs Filename:=WshShell.SpecialFolders("Desktop") & "\Copreco
Reading.xlsx """

================================================
Sub ExportCoprecoReadingData()
Const sourceSheet = "Site Reading Log" ' source
Dim sourceBook As String
Dim destBook As String
Dim sourceRange As Range
Dim destRange As Range

Application.ScreenUpdating = False
sourceBook = ThisWorkbook.Name
'get the new workbook object
Set sbFile = Workbooks.Add ' create new book
destBook = ActiveWorkbook.Name
Windows(sourceBook).Activate
Worksheets(sourceSheet).Select

Set sourceRange = ActiveSheet.Rows("1:1")
Set destRange = Workbooks(destBook).Worksheets("Sheet1").Rows("1:1 ")
destRange.Value = sourceRange.Value

'change "A" to column with data in last row
Range("A" & Rows.Count).End(xlUp).Select
Set sourceRange = ActiveSheet.Rows(ActiveCell.Row & ":" & ActiveCell.Row)
Set destRange = Workbooks(destBook).Worksheets("Sheet1").Rows("2:2 ")
destRange.Value = sourceRange.Value
Set sourceRange = Nothing
Set destRange = Nothing

'get the desktop path, save and close new workbook
Set WshShell = CreateObject("WScript.Shell")
sbFile.SaveAs Filename:=WshShell.SpecialFolders("Desktop") & "\Copreco
Reading.xlsx """
sbFile.Close

Set WshShell = Nothing
Set sbFile = Nothing

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Runtime Error 1004 - File could not be accessed

It failed the second time for me because the item was already on my desktop.
The 1st time it ran perfectly.

"Carlee" wrote:

Hi there, i am getting a runtime error 1004...that the file could not be
accessed. The code it below, and the line in question is:

sbFile.SaveAs Filename:=WshShell.SpecialFolders("Desktop") & "\Copreco
Reading.xlsx """

================================================
Sub ExportCoprecoReadingData()
Const sourceSheet = "Site Reading Log" ' source
Dim sourceBook As String
Dim destBook As String
Dim sourceRange As Range
Dim destRange As Range

Application.ScreenUpdating = False
sourceBook = ThisWorkbook.Name
'get the new workbook object
Set sbFile = Workbooks.Add ' create new book
destBook = ActiveWorkbook.Name
Windows(sourceBook).Activate
Worksheets(sourceSheet).Select

Set sourceRange = ActiveSheet.Rows("1:1")
Set destRange = Workbooks(destBook).Worksheets("Sheet1").Rows("1:1 ")
destRange.Value = sourceRange.Value

'change "A" to column with data in last row
Range("A" & Rows.Count).End(xlUp).Select
Set sourceRange = ActiveSheet.Rows(ActiveCell.Row & ":" & ActiveCell.Row)
Set destRange = Workbooks(destBook).Worksheets("Sheet1").Rows("2:2 ")
destRange.Value = sourceRange.Value
Set sourceRange = Nothing
Set destRange = Nothing

'get the desktop path, save and close new workbook
Set WshShell = CreateObject("WScript.Shell")
sbFile.SaveAs Filename:=WshShell.SpecialFolders("Desktop") & "\Copreco
Reading.xlsx """
sbFile.Close

Set WshShell = Nothing
Set sbFile = Nothing

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
runtime 1004 error Janis Excel Programming 3 September 14th 06 09:52 PM
runtime error 1004 saveas text file Janis Excel Programming 2 September 1st 06 11:11 PM
File Name Causes Runtime Error 1004 Robert Excel Programming 1 November 10th 05 02:47 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
runtime error 1004 when opening excel file via VBA in a browser Ken Hunter Excel Programming 2 July 31st 03 03:33 PM


All times are GMT +1. The time now is 12:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"