-
September 23rd, 2016, 09:32 AM
#1
Accessing a file on a remote computer
I am trying to read the contents of an excel file located on another computer.
Could someone please help me to achieve this. I have been looking on the
Internet, but without any good example.
below is what I have got so far....
Thanks in advance
Private Sub Form_Load()
Dim excelApp As Excel.Application
Dim excelWS As Excel.Worksheet
Set excelApp = CreateObject("Excel.Application")
Set excelWB = excelApp.Workbooks.Open("\\ncccurr04\c:\Users\Desktop\documents\staff.xlsx")
Set excelWS = excelWB.Worksheets(1)
excelApp.Visible = True
End Sub
-
September 23rd, 2016, 02:00 PM
#2
Re: Accessing a file on a remote computer
Is the drive shared?
If so what is the share name and what is shared?
Are you sure your path is correct, usually the desktop folder would be in a sub folder of users, that sub folder being the users account folder
c:\Users\SomeUser\desktop
If the computer is on your Lan and the location is shared then it is a simple thing but you must use the proper share name.
If the computer is not on your Lan then that is another story.
Last edited by DataMiser; September 23rd, 2016 at 02:03 PM.
Always use [code][/code] tags when posting code.
-
September 27th, 2016, 04:24 AM
#3
Re: Accessing a file on a remote computer
Ok... the drive is not shared and the remote computer is on the same lan.
-
September 27th, 2016, 08:53 AM
#4
Re: Accessing a file on a remote computer
The file must be in a shared location that you have access to from the pc and user account in question.
Always use [code][/code] tags when posting code.
-
October 5th, 2016, 06:33 AM
#5
Re: Accessing a file on a remote computer
Originally Posted by DataMiser
The file must be in a shared location that you have access to from the pc and user account in question.
ok... I'll try this and see if it works....
Thanks
-
October 17th, 2016, 09:03 AM
#6
Re: Accessing a file on a remote computer
Still didn't work.... can someone please help me?
-
October 17th, 2016, 10:23 PM
#7
Re: Accessing a file on a remote computer
What did you actually try?
Always use [code][/code] tags when posting code.
-
October 21st, 2016, 04:27 AM
#8
Re: Accessing a file on a remote computer
Originally Posted by DataMiser
What did you actually try?
I have ensured that the file is in a shared location and that the program have access to it.
I have also run the program with administrator credentials.
Both computers are on the same LAN
Remote file location is set in the following line:-
Set excelWB = excelApp.Workbooks.Open("\\ncccurr04\c:\Users\Desktop\documents\staff.xlsx")
-
October 21st, 2016, 08:22 AM
#9
Re: Accessing a file on a remote computer
That is an odd path. Normally the desktop folder is contained in a sub folder within the users folder.
Of course I can't really say what your problem is at this point as I have no idea what you shared, how you shared it nor what error you are now getting.
Did you shared the drive? Did you share it as C? Or did you share a folder and/or did you give the share a name? What error are you getting now?
Always use [code][/code] tags when posting code.
-
October 21st, 2016, 08:47 AM
#10
Re: Accessing a file on a remote computer
Code:
"\\ncccurr04\c:\Users\Desktop\documents\staff.xlsx"
That is not a correct reference to a share. The format to connect via a share using Universal Naming Convention is
Code:
\\computername\sharename\<folders and/or filename relative to the share>
See https://support.microsoft.com/en-us/kb/323386
On the computer to which you want to connect, what folder have you shared and what name did you give to this share? What permissions did you set for the share?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 21st, 2016, 09:18 AM
#11
Re: Accessing a file on a remote computer
To determine what shares are available for ncccurr04 computer, from a command prompt do
Code:
net view \\ncccurr04
You should see a list of shares of type disk. If you don't or if you get an error then there is a problem with the network and/or the shares on ncccurr04.
If an error does occur, first try
That will show the names of all the available domains and workgroups. Then for the domain/workgroup in which computer ncccurr04 is a member (say eg workgroup) then try
Code:
net view /domain:workgroup
If that completes successfully, then the issue is with the share. If any of these don't then the issue is a networking one.
Last edited by 2kaud; October 21st, 2016 at 09:40 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 25th, 2016, 08:53 AM
#12
Re: Accessing a file on a remote computer
Thanks for that... all commands ran successfully without any errors but,
because there was a significant time lap in getting back any response, I redesigned the program looking at things from another perspective in an effort to move forward.
So instead of trying to open the excel file on the remote machine Set excelWB = excelApp.Workbooks.Open("\\ncccurr04\c:\Users\Desktop\documents\staff.xlsx")
I am now thinking it might be easier to copy the remote file to the local machine then open it.
So I ended up with the new code below which again doesn't work due to network issues
Code:
Private Sub Form_Load()
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder As String
'source folder path on remote machine.
sSFolder = "\\ncccurr04\c:\Users\grossett.adm\Desktop\documents"
sFile = "staff.xlsx"
'destination path on local machine.
sDFolder = "c:\"
'Create Object for File System
Set FSO = CreateObject("Scripting.FileSystemObject")
'Checking If File Is Located in the Source Folder
If Not FSO.FileExists(sSFolder & sFile) Then
MsgBox "Specified File Not Found in Source Folder", vbInformation, "Not Found"
'Copying If the Same File is Not Located in the Destination Folder
ElseIf Not FSO.FileExists(sDFolder & sFile) Then
FSO.CopyFile (sSFolder & sFile), sDFolder, True
MsgBox "Specified File Copied to Destination Folder Successfully", vbInformation, "Done!"
Else
MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists"
End If
End Sub
This display the following message.... Specified File Not Found in Source Folder even though the file is there.
Last edited by 2kaud; October 25th, 2016 at 09:06 AM.
-
October 25th, 2016, 09:07 AM
#13
Re: Accessing a file on a remote computer
Code:
sSFolder = "\\ncccurr04\c:\Users\grossett.adm\Desktop\documents"
As I explained in post #10, that is not a correct path reference to a share on a remote computer. As all the commands worked OK, what is the display from
Code:
net view \\ncccurr04
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 26th, 2016, 08:50 AM
#14
Re: Accessing a file on a remote computer
Yes... I kinda figure something wrong with my/file path...(thanks!). First thing first,
When I executed the command net view \\ncccurr04 the following was displayed
Share name Type Used as Comment
------------------------------------------------
documents Disk
Users Disk
The command completed successfully
When I executed the command net view /domain the following was displayed
NEWMANCC
WORKGROUP
ZPRESENT
The command completed successfully
When I executed the command net view /domain:workgroup the following was displayed
Server Name Remark
------------------------------------------------
\\ITTECHLENOVO
\\M46 M46
The command completed successfully
From these results... can you explain how to resolve my problem andor what I am doing wrong?
Thanks
-
October 26th, 2016, 10:06 AM
#15
Re: Accessing a file on a remote computer
For the computer \\ncccurr04 there are 2 shares present documents and Users. From this I would suggest
Code:
sSFolder = "\\ncccurr04\Users\grossett.adm\Desktop\documents"
However, depending upon the location to where the share documents points, you may be able to have
Code:
sSFolder = "\\ncccurr04\documents"
However, the problem you then might have are the permissions for the folder/file you want to access. These will need to allow read access to these folders/files on computer ncccurr04 from the user/computer you are trying to access from.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
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
|