Having trouble with scripts

bhachug

New Member
Joined
Sep 30, 2011
Messages
15
So I've created a form which I hoped would have been able to input the values of strDriveLetter, strRemoteMap, strUser, strPassword manually (allowing more flexibility in case the location changed) but have been unable to call FORMSTART. I designed FORMSTART for the function of allowing the user to manually input the names however I keep getting a compiler error when running the script. I get it when I try to call FORMSTART and it tells me its "invalid outside the procedure". I've never worked with scripts before this so I'm unsure if I'm even allowed to call a subroutine inside of a script. Any help would be very much appreciated. Thanks guys.

BTW I'm hoping to be able to delete the green part so the user is able to input the values through textboxes in the userform (also my first project incorporating userforms).

Also this is a script so I think that explains why you don't need a sub or function.

Rich (BB code):
Option Explicit
Dim strDriveLetter, strRemoteMap, strUser, strPassword
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
 
Call FORMSTART
 
' Set the variables.
 
strDriveLetter.Value = "V:"
strRemoteMap.Value = "\\AEC-PC2-C1\PC2_AOI"
strUser.Value = "itac"
strPassword.Value = "easy"
 
 More code which incorporate the variables declared above.
<MORE CODE>
 
 
WScript.Quit
' Script ends
 
 
Sub FORMSTART()
Form1.Show
End Sub
 
Private Sub UserForm_Initialize()
Form1.Show
strDriveLettertb.Value = ""
strRemoteMaptb.Value = ""
strUsertb.Value = ""
strPasswordtb.Value = ""
strDriveLettertb.Focus
End Sub
 
Private Sub Clear_Click()
Call UserForm_Initialize
End Sub
 
Private Sub Go_Click()
strDriveLetter.Value = strDriveLettertb.Value
strRemoteMap.Value = strRemoteMaptb.Value
strUser.Value = strUsertb.Value
strPassword.Value = strPasswordtb.Value
End Sub
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Put this portion of the code inside a Procedure like



Code:
[B][COLOR=#ff0000]Sub Test()[/COLOR][/B]
 
Dim strDriveLetter, strRemoteMap, strUser, strPassword
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
 
Call FORMSTART
 
' Set the variables.
 
strDriveLetter.Value = "V:"
strRemoteMap.Value = "[URL="file://\\AEC-PC2-C1\PC2_AOI"]\\AEC-PC2-C1\PC2_AOI[/URL]"
strUser.Value = "itac"
strPassword.Value = "easy"
 
' More code which incorporate the variables declared above.
 
 
WScript.Quit
 
[B][COLOR=red]End Sub[/COLOR][/B]
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top