Results 1 to 4 of 4

Thread: Gathering Data from a NetWork File

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    2

    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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Gathering Data from a NetWork File

    you can try this, i have done some of this in the past with .xls

    vb Code:
    1. dim myarr as variant
    2. set wb = getobject(strFileToOpen)
    3. myarr = wb.sheets("sheet7").range("a1:g75")
    4. set wb = nothing
    5. 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

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    2

    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

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
  •  



Click Here to Expand Forum to Full Width