|
-
May 5th, 2011, 05:39 AM
#1
Thread Starter
New Member
Gathering Data from a NetWork File
HI all,
I need your experiance to overcome what I originaly thought was a simple issue.
I need to Pull Data from an open workbook on a network PC, without opening the workbook on my PC. I have the following code which deterimins if the Workbook is Open on the Target Network Drive, but I'm stuck on how to upload / copy in essence Data from it?
Sub Network_File_Open()
Const strFileToOpen As String = "Q:\PathName\Filename1.xlsm"
If IsFileOpen(strFileToOpen) Then
MsgBox strFileToOpen & " is already Open"
Else
MsgBox strFileToOpen & " is not open", vbInformation
End If
End Sub
Function IsFileOpen(strFullPathFileName As String) As Boolean
Dim hdlFile As Long
'Error is generated if you try
'opening a File for ReadWrite lock >> MUST BE OPEN!
On Error GoTo FileIsOpen:
hdlFile = FreeFile
Open strFullPathFileName For Random Access Read Write Lock Read Write As hdlFile
IsFileOpen = False
Close hdlFile
Exit Function
FileIsOpen:
'Someone has it open!
IsFileOpen = True
Close hdlFile
End Function
The above function works fine how do I now pull data from say Sheet7.Range("A1:G75") , Could be smaller or larger though: and then copy it into my workbook. or enter values into an array on my workbook.
Hoping you can assist
Lee
-
May 5th, 2011, 07:56 AM
#2
Re: Gathering Data from a NetWork File
you can try this, i have done some of this in the past with .xls
vb Code:
dim myarr as variant
set wb = getobject(strFileToOpen)
myarr = wb.sheets("sheet7").range("a1:g75")
set wb = nothing
thisworkbook.sheets("sheet1").range("c6").resize(75,7).value = myarr
change destination sheet /range etc to suit
i would not recommend editing the remote workbook, using this method, as i am not sure what the results would be
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 5th, 2011, 08:21 AM
#3
Thread Starter
New Member
Re: Gathering Data from a NetWork File
Many thanks for a quick reply.
I have entered the snippet that you supplied & Dim Wb as Workbook, as variant and as Object
However these all produce an Unspecified Error , Automation Error
any thoughts
Rgds Lee
-
May 5th, 2011, 08:46 AM
#4
Re: Gathering Data from a NetWork File
it may require a unc path, though i do not know why it should, but that is what i was using at the time as the drive was not mapped
it was quite some time ago i messed around with this, and i am not, currently, in a position to be able to test this at all (no network here)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|