-
Mar 6th, 2024, 05:05 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Determine which computer is running Excel file
I have model in Excel that are run from two different computers (a desktop and a laptop). The model uses a file to import data that is located in a OneDrive folder. The path to that OneDrive folder differs on the two computers. I then have a Const that is set to the OneDrive folder so the model know where to find the file for the import.
Is there a way in VBA I can detect, at startup, which computer is running the model and then set the Const programmatically to the correct folder? Something like:
Code:
If 'Computer is Desktop' then
Const FS_Intermediate_File as String = 'path to OneDrive folder on desktop'
ElseIf 'Computer is Laptop' then
Const FS_Intermediate_File as String = 'path to OneDrive folder on laptop'
End If
Currently I change the Const declaration manually
-
Mar 6th, 2024, 05:19 AM
#2
Re: Determine which computer is running Excel file
Don't put in a Const but in a Public variable.
-
Mar 6th, 2024, 06:19 AM
#3
Re: Determine which computer is running Excel file
You could use the Environ function to look at the computer name https://vbaf1.com/variables/environment/
Code:
If Environ("COMPUTERNAME") = "[your desktop computers name]" then
FS_Intermediate_File as String = 'path to OneDrive folder on desktop'
ElseIf Environ("COMPUTERNAME") = "[your laptop computers name]" then
FS_Intermediate_File as String = 'path to OneDrive folder on laptop'
End If
-
Mar 7th, 2024, 03:45 AM
#4
Thread Starter
Hyperactive Member
Re: Determine which computer is running Excel file
 Originally Posted by jdelano
You could use the Environ function to look at the computer name https://vbaf1.com/variables/environment/
Code:
If Environ("COMPUTERNAME") = "[your desktop computers name]" then
FS_Intermediate_File as String = 'path to OneDrive folder on desktop'
ElseIf Environ("COMPUTERNAME") = "[your laptop computers name]" then
FS_Intermediate_File as String = 'path to OneDrive folder on laptop'
End If
Where would the best place be to put this code so that it executes on opening the workbook? Don't know what executes when
Not too worry. Found Workbook_Open
Last edited by Bezzie; Mar 7th, 2024 at 05:44 AM.
-
Mar 7th, 2024, 10:20 AM
#5
Re: [RESOLVED] Determine which computer is running Excel file
There you go
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
|