ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding data to a closed sheet (https://www.excelbanter.com/excel-programming/412181-adding-data-closed-sheet.html)

dan

Adding data to a closed sheet
 
Will it be possible to copy data (6 consecutive cells) from my current sheet
to the end of another sheet that is not currently open.
Many thanks
Dan

Gary''s Student

Adding data to a closed sheet
 
1. open the closed workbook
2. perform the copy/paste
3. re-close the previously closed workbook
--
Gary''s Student - gsnu200790


"Dan" wrote:

Will it be possible to copy data (6 consecutive cells) from my current sheet
to the end of another sheet that is not currently open.
Many thanks
Dan


Ron de Bruin

Adding data to a closed sheet
 
Hi Dan, try
http://www.rondebruin.nl/copy1.htm

See the last example
"What if the Database sheet is in another workbook"




--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dan" wrote in message ...
Will it be possible to copy data (6 consecutive cells) from my current sheet
to the end of another sheet that is not currently open.
Many thanks
Dan


John

Adding data to a closed sheet
 
Hi Dan,
Gary's resopnse is correct but to give a little more meat to bones of what
he is saying an approach along the lines of following could be used. The
FileLocked function checks to see if the file is already open read / write
mode. This is not something I have written (sorry to author for not giving
credit) but I make extensive use of it in various applications. You should
get the general idea of how to apply what Gary was saying to.

Hope helpful

Sub AddToFile()
Dim DestWB As Workbook
Dim DBFile As String
Dim mytitle As String

mytitle = "Add Data To File"

DBFile = "C:\WhichDirectory\WhichFile.xls" '<< change as required

'Check if Read / Write File Already Open
If FileLocked(DBFile) Then
msg = MsgBox("Read / Write File Already Open.", 16, mytitle)

Else
Set DestWB = Workbooks.Open(DBFile, Password:="mypassword")

'do your stuff here

DestWB.Close True

End If
End Sub

Function FileLocked(strFileName As String) As Boolean

On Error Resume Next

' If the file is already opened by another process,
' and the specified type of access is not allowed,
' the Open operation fails and an error occurs.
Open strFileName For Binary Access Read Lock Read As #1
Close #1

' If an error occurs, the document is currently open.
If Err.Number < 0 Then
FileLocked = True
Err.Clear
End If
On Error GoTo 0
End Function





--
jb


"Dan" wrote:

Will it be possible to copy data (6 consecutive cells) from my current sheet
to the end of another sheet that is not currently open.
Many thanks
Dan



All times are GMT +1. The time now is 10:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com