msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reading cells from Excel

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
joeroc



Joined: 04 Oct 2007
Posts: 5

PostPosted: Mon Jun 26, 2006 6:13 pm    Post subject: Reading cells from Excel Reply with quote

The following script allows me to remap network drives that are aleady in
use. I however would like to pull the drives and share info from an excel
spreadsheet instead of having to edit the vb file itself. Can anyone get me
started on this as I'm eager to learn and am a scripting newbie.

'DEFINE DRIVES TO MAP:
'________________________________________________________

Mapit "V", "\\nycfinmf1\apps"
Mapit "W", "\\nycfinmf1\apps"
'_________________________________________________________
'SUb
'_________________________________________________________

Sub Mapit(strLetter, strPath)

'Slight puase to ensure each pass has time to commit:
wscript.sleep 200

'Define whether the map infor should be removed from the current user's
profile
bForceRemoveFromProfile = True
bRemovefromprofile = True

'Define wheter the map info should be stored in the current user's profile
bStoreinProfile = True

Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set oDrives = ObjNetwork.EnumNetworkDrives()

'Define the DriveLetter:
DriveLetter = strLetter & ":"

'Define the remote path
Remotepath = strPath

'Check if already connected:
AlreadyConnected = False
For i = 0 to oDrives.Count - 1 step 2
if LCase(oDrives.Item(i)) = LCase(DriveLetter) Then AlreadyConnected = True
Next

'Attempt to map the drive. If already mapped, first attempt to disconnect
If AlreadyConnected = True Then
ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
bForceRemoveFromProfile
ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
Else
ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
End If
End Sub
Wscript.Quit

Archived from group: microsoft>public>vb>syntax
Back to top
View user's profile Send private message
Richard Mueller



Joined: 04 Oct 2007
Posts: 15

PostPosted: Mon Jun 26, 2006 10:33 pm    Post subject: Re: Reading cells from Excel Reply with quote

Hi,

Seems like it would as easy to modify the VB file as to modify an Excel
spreadsheet. Also, everyone using the script must have read access to the
spreadsheet. Here is a solution. This requires that Excel be installed on
the machine running the program. For each row of the spreadsheet, the first
column is the drive letter (without the colon), the second column is the unc
path to be mapped to the drive.
====================
' Specify Excel spreadsheet.
strExcelPath = "\\MyServer\MyShare\Drives.xls"

' Setup Excel object.
Set objExcel = CreateObject("Excel.Application")

' Open specified spreadsheet and select the first worksheet.
objExcel.WorkBooks.Open strExcelPath
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' Read each row of the spreadsheet until a blank is found
' in the first column. Start with row 1.
intRow = 1
Do While objSheet.Cells(intRow, 1).Value ""
strDrive = objSheet.Cells(intRow, 1).Value
strPath = objSheet.Cells(intRow, 2).Value
Mapit strDrive, strPath
intRow = intRow + 1
Loop

' Close workbook and quit Excel.
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

' Clean up.
Set objExcel = Nothing
Set objSheet = Nothing
==================

Also, your subroutine can be made more efficient by binding to the wshShell
and wshNetwork objects elsewhere with global or module level scope. Your
subroutine maps to these objects repeatedly for each drive letter to be
mapped. (Actually, objShell is not used, so this can be removed.) Also, you
enumerate all drives repeatedly for each drive letter. I would attempt to
map the drive and trap the error if it cannot be mapped, then remove the
mapping. For example:

' Bind to wshNetwork object at module level.
Set m_objNetwork = CreateObject("Wscript.Network")

Sub Mapit(strLetter, strPath)
'Define whether the map info should be removed from the current user's
profile
bForceRemoveFromProfile = True
bRemovefromprofile = True

'Define wheter the map info should be stored in the current user's
profile
bStoreinProfile = True

'Define the DriveLetter:
DriveLetter = strLetter & ":"

'Define the remote path
Remotepath = strPath

' Attempt to map drive. Trap error if drive letter already mapped.
On Error Resume Next
ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
If (Err.Number 0) Then
On Error GoTo 0
ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
bForceRemoveFromProfile
ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
End If
On Error GoTo 0

End Sub

However, you subroutine should work fine, so the above is a minor point. I
see no need for the pause in the subroutine. I cannot recall any cases where
such a pause has been needed.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"joeroc" wrote in message @microsoft.com...
> The following script allows me to remap network drives that are aleady in
> use. I however would like to pull the drives and share info from an excel
> spreadsheet instead of having to edit the vb file itself. Can anyone get
> me
> started on this as I'm eager to learn and am a scripting newbie.
>
> 'DEFINE DRIVES TO MAP:
> '________________________________________________________
>
> Mapit "V", "\\nycfinmf1\apps"
> Mapit "W", "\\nycfinmf1\apps"
> '_________________________________________________________
> 'SUb
> '_________________________________________________________
>
> Sub Mapit(strLetter, strPath)
>
> 'Slight puase to ensure each pass has time to commit:
> wscript.sleep 200
>
> 'Define whether the map infor should be removed from the current user's
> profile
> bForceRemoveFromProfile = True
> bRemovefromprofile = True
>
> 'Define wheter the map info should be stored in the current user's profile
> bStoreinProfile = True
>
> Set objShell = CreateObject("WScript.Shell")
> Set objNetwork = CreateObject("WScript.Network")
> Set oDrives = ObjNetwork.EnumNetworkDrives()
>
> 'Define the DriveLetter:
> DriveLetter = strLetter & ":"
>
> 'Define the remote path
> Remotepath = strPath
>
> 'Check if already connected:
> AlreadyConnected = False
> For i = 0 to oDrives.Count - 1 step 2
> if LCase(oDrives.Item(i)) = LCase(DriveLetter) Then AlreadyConnected =
> True
> Next
>
> 'Attempt to map the drive. If already mapped, first attempt to disconnect
> If AlreadyConnected = True Then
> ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
> bForceRemoveFromProfile
> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> Else
> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> End If
> End Sub
> Wscript.Quit
Back to top
View user's profile Send private message
joeroc



Joined: 04 Oct 2007
Posts: 5

PostPosted: Tue Jun 27, 2006 3:07 pm    Post subject: Re: Reading cells from Excel Reply with quote

Richard,

Thanks for your help. When testing the app i have about 7 different drives
being mapped via the Apps.xls spreadsheet and have to run the file at least 3
times in order to have them all mapped as only several get mapped on the
first run and second run. Can i move the wscript.sleep 200 request to
another part of the scirpt in order to give it time to complete the previous
mapping before going onto the next one?


'Specify Excel Spreadsheet
strExcelPath = "C:\Scripts\Apps.xls"

'Create Excel Object
Set objExcel = CreateObject("Excel.Application")

'Open specified spreadsheet and select the first worksheet
objExcel.WorkBooks.Open strExcelPath
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

'Read each row of the spreadsheet until a blank is found
'in the first column. Start with row 2
intRow = 2
Do While objSheet.Cells(intRow, 1).Value ""
strDrive = objSheet.Cells(intRow, 1).Value
strPath = objSheet.Cells(intRow, 2).Value
Mapit strDrive, strPath
intRow = intRow + 1
Loop

'Close workbook and quit Excel
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

'Clean up
Set objExcel = Nothing
Set objSheet = Nothing
'________________________________________________________
'SUb
'_________________________________________________________

Sub Mapit(strLetter, strPath)

'Slight puase to ensure each pass has time to commit:
wscript.sleep 200

'Define whether the map infor should be removed from the current user's
profile
bForceRemoveFromProfile = True
bRemovefromprofile = True

'Define wheter the map info should be stored in the current user's profile
bStoreinProfile = True

'Bind to wshNetwork object at module level
Set objNetwork = CreateObject("WScript.Network")

'Define the DriveLetter:
DriveLetter = strLetter & ":"

'Define the remote path
Remotepath = strPath

'Attempt to map drive. Trap error if drive letter already mapped
On Error Resume Next
objNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
If (Err.Number 0) Then
On Error GoTo 0
ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
bForceRemoveFromProfile
ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
End If
On Error GoTo 0

End Sub

"Richard Mueller" wrote:

> Hi,
>
> Seems like it would as easy to modify the VB file as to modify an Excel
> spreadsheet. Also, everyone using the script must have read access to the
> spreadsheet. Here is a solution. This requires that Excel be installed on
> the machine running the program. For each row of the spreadsheet, the first
> column is the drive letter (without the colon), the second column is the unc
> path to be mapped to the drive.
> ====================
> ' Specify Excel spreadsheet.
> strExcelPath = "\\MyServer\MyShare\Drives.xls"
>
> ' Setup Excel object.
> Set objExcel = CreateObject("Excel.Application")
>
> ' Open specified spreadsheet and select the first worksheet.
> objExcel.WorkBooks.Open strExcelPath
> Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
>
> ' Read each row of the spreadsheet until a blank is found
> ' in the first column. Start with row 1.
> intRow = 1
> Do While objSheet.Cells(intRow, 1).Value ""
> strDrive = objSheet.Cells(intRow, 1).Value
> strPath = objSheet.Cells(intRow, 2).Value
> Mapit strDrive, strPath
> intRow = intRow + 1
> Loop
>
> ' Close workbook and quit Excel.
> objExcel.ActiveWorkbook.Close
> objExcel.Application.Quit
>
> ' Clean up.
> Set objExcel = Nothing
> Set objSheet = Nothing
> ==================
>
> Also, your subroutine can be made more efficient by binding to the wshShell
> and wshNetwork objects elsewhere with global or module level scope. Your
> subroutine maps to these objects repeatedly for each drive letter to be
> mapped. (Actually, objShell is not used, so this can be removed.) Also, you
> enumerate all drives repeatedly for each drive letter. I would attempt to
> map the drive and trap the error if it cannot be mapped, then remove the
> mapping. For example:
>
> ' Bind to wshNetwork object at module level.
> Set m_objNetwork = CreateObject("Wscript.Network")
>
> Sub Mapit(strLetter, strPath)
> 'Define whether the map info should be removed from the current user's
> profile
> bForceRemoveFromProfile = True
> bRemovefromprofile = True
>
> 'Define wheter the map info should be stored in the current user's
> profile
> bStoreinProfile = True
>
> 'Define the DriveLetter:
> DriveLetter = strLetter & ":"
>
> 'Define the remote path
> Remotepath = strPath
>
> ' Attempt to map drive. Trap error if drive letter already mapped.
> On Error Resume Next
> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> If (Err.Number 0) Then
> On Error GoTo 0
> ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
> bForceRemoveFromProfile
> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> End If
> On Error GoTo 0
>
> End Sub
>
> However, you subroutine should work fine, so the above is a minor point. I
> see no need for the pause in the subroutine. I cannot recall any cases where
> such a pause has been needed.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
> "joeroc" wrote in message
> @microsoft.com...
> > The following script allows me to remap network drives that are aleady in
> > use. I however would like to pull the drives and share info from an excel
> > spreadsheet instead of having to edit the vb file itself. Can anyone get
> > me
> > started on this as I'm eager to learn and am a scripting newbie.
> >
> > 'DEFINE DRIVES TO MAP:
> > '________________________________________________________
> >
> > Mapit "V", "\\nycfinmf1\apps"
> > Mapit "W", "\\nycfinmf1\apps"
> > '_________________________________________________________
> > 'SUb
> > '_________________________________________________________
> >
> > Sub Mapit(strLetter, strPath)
> >
> > 'Slight puase to ensure each pass has time to commit:
> > wscript.sleep 200
> >
> > 'Define whether the map infor should be removed from the current user's
> > profile
> > bForceRemoveFromProfile = True
> > bRemovefromprofile = True
> >
> > 'Define wheter the map info should be stored in the current user's profile
> > bStoreinProfile = True
> >
> > Set objShell = CreateObject("WScript.Shell")
> > Set objNetwork = CreateObject("WScript.Network")
> > Set oDrives = ObjNetwork.EnumNetworkDrives()
> >
> > 'Define the DriveLetter:
> > DriveLetter = strLetter & ":"
> >
> > 'Define the remote path
> > Remotepath = strPath
> >
> > 'Check if already connected:
> > AlreadyConnected = False
> > For i = 0 to oDrives.Count - 1 step 2
> > if LCase(oDrives.Item(i)) = LCase(DriveLetter) Then AlreadyConnected =
> > True
> > Next
> >
> > 'Attempt to map the drive. If already mapped, first attempt to disconnect
> > If AlreadyConnected = True Then
> > ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
> > bForceRemoveFromProfile
> > ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> > Else
> > ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> > End If
> > End Sub
> > Wscript.Quit
>
>
>
Back to top
View user's profile Send private message
joeroc



Joined: 04 Oct 2007
Posts: 5

PostPosted: Tue Jun 27, 2006 3:16 pm    Post subject: Re: Reading cells from Excel Reply with quote

Richard,

I've added wscript.sleep 200 to the following part of the script right after
ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile and the
script now maps the drives in one run. I'm going to try and come up with a
script that will pull the currently mapped drives from a user and populate
the excel file. I'm sure i won't be able to do it right the first time so
i'll be posting soon enough.

> ' Attempt to map drive. Trap error if drive letter already mapped.
> On Error Resume Next
> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> If (Err.Number 0) Then
> On Error GoTo 0
> ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
> bForceRemoveFromProfile
> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> wscript.sleep 200
> End If
> On Error GoTo 0

"Richard Mueller" wrote:

> Hi,
>
> Seems like it would as easy to modify the VB file as to modify an Excel
> spreadsheet. Also, everyone using the script must have read access to the
> spreadsheet. Here is a solution. This requires that Excel be installed on
> the machine running the program. For each row of the spreadsheet, the first
> column is the drive letter (without the colon), the second column is the unc
> path to be mapped to the drive.
> ====================
> ' Specify Excel spreadsheet.
> strExcelPath = "\\MyServer\MyShare\Drives.xls"
>
> ' Setup Excel object.
> Set objExcel = CreateObject("Excel.Application")
>
> ' Open specified spreadsheet and select the first worksheet.
> objExcel.WorkBooks.Open strExcelPath
> Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
>
> ' Read each row of the spreadsheet until a blank is found
> ' in the first column. Start with row 1.
> intRow = 1
> Do While objSheet.Cells(intRow, 1).Value ""
> strDrive = objSheet.Cells(intRow, 1).Value
> strPath = objSheet.Cells(intRow, 2).Value
> Mapit strDrive, strPath
> intRow = intRow + 1
> Loop
>
> ' Close workbook and quit Excel.
> objExcel.ActiveWorkbook.Close
> objExcel.Application.Quit
>
> ' Clean up.
> Set objExcel = Nothing
> Set objSheet = Nothing
> ==================
>
> Also, your subroutine can be made more efficient by binding to the wshShell
> and wshNetwork objects elsewhere with global or module level scope. Your
> subroutine maps to these objects repeatedly for each drive letter to be
> mapped. (Actually, objShell is not used, so this can be removed.) Also, you
> enumerate all drives repeatedly for each drive letter. I would attempt to
> map the drive and trap the error if it cannot be mapped, then remove the
> mapping. For example:
>
> ' Bind to wshNetwork object at module level.
> Set m_objNetwork = CreateObject("Wscript.Network")
>
> Sub Mapit(strLetter, strPath)
> 'Define whether the map info should be removed from the current user's
> profile
> bForceRemoveFromProfile = True
> bRemovefromprofile = True
>
> 'Define wheter the map info should be stored in the current user's
> profile
> bStoreinProfile = True
>
> 'Define the DriveLetter:
> DriveLetter = strLetter & ":"
>
> 'Define the remote path
> Remotepath = strPath
>
> ' Attempt to map drive. Trap error if drive letter already mapped.
> On Error Resume Next
> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> If (Err.Number 0) Then
> On Error GoTo 0
> ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
> bForceRemoveFromProfile
> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> End If
> On Error GoTo 0
>
> End Sub
>
> However, you subroutine should work fine, so the above is a minor point. I
> see no need for the pause in the subroutine. I cannot recall any cases where
> such a pause has been needed.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
> "joeroc" wrote in message
> @microsoft.com...
> > The following script allows me to remap network drives that are aleady in
> > use. I however would like to pull the drives and share info from an excel
> > spreadsheet instead of having to edit the vb file itself. Can anyone get
> > me
> > started on this as I'm eager to learn and am a scripting newbie.
> >
> > 'DEFINE DRIVES TO MAP:
> > '________________________________________________________
> >
> > Mapit "V", "\\nycfinmf1\apps"
> > Mapit "W", "\\nycfinmf1\apps"
> > '_________________________________________________________
> > 'SUb
> > '_________________________________________________________
> >
> > Sub Mapit(strLetter, strPath)
> >
> > 'Slight puase to ensure each pass has time to commit:
> > wscript.sleep 200
> >
> > 'Define whether the map infor should be removed from the current user's
> > profile
> > bForceRemoveFromProfile = True
> > bRemovefromprofile = True
> >
> > 'Define wheter the map info should be stored in the current user's profile
> > bStoreinProfile = True
> >
> > Set objShell = CreateObject("WScript.Shell")
> > Set objNetwork = CreateObject("WScript.Network")
> > Set oDrives = ObjNetwork.EnumNetworkDrives()
> >
> > 'Define the DriveLetter:
> > DriveLetter = strLetter & ":"
> >
> > 'Define the remote path
> > Remotepath = strPath
> >
> > 'Check if already connected:
> > AlreadyConnected = False
> > For i = 0 to oDrives.Count - 1 step 2
> > if LCase(oDrives.Item(i)) = LCase(DriveLetter) Then AlreadyConnected =
> > True
> > Next
> >
> > 'Attempt to map the drive. If already mapped, first attempt to disconnect
> > If AlreadyConnected = True Then
> > ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
> > bForceRemoveFromProfile
> > ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> > Else
> > ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
> > End If
> > End Sub
> > Wscript.Quit
>
>
>
Back to top
View user's profile Send private message
Richard Mueller



Joined: 04 Oct 2007
Posts: 15

PostPosted: Tue Jun 27, 2006 7:05 pm    Post subject: Re: Reading cells from Excel Reply with quote

Interesting. I don't understand why it's needed, but if it works, great. I
guess I've never mapped more than about 3 drives in a logon script before.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"joeroc" wrote in message @microsoft.com...
> Richard,
>
> I've added wscript.sleep 200 to the following part of the script right
> after
> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile and
> the
> script now maps the drives in one run. I'm going to try and come up with
> a
> script that will pull the currently mapped drives from a user and populate
> the excel file. I'm sure i won't be able to do it right the first time so
> i'll be posting soon enough.
>
>> ' Attempt to map drive. Trap error if drive letter already mapped.
>> On Error Resume Next
>> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
>> If (Err.Number 0) Then
>> On Error GoTo 0
>> ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
>> bForceRemoveFromProfile
>> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath,
>> bStoreInProfile
>> wscript.sleep 200
>> End If
>> On Error GoTo 0
>
> "Richard Mueller" wrote:
>
>> Hi,
>>
>> Seems like it would as easy to modify the VB file as to modify an Excel
>> spreadsheet. Also, everyone using the script must have read access to the
>> spreadsheet. Here is a solution. This requires that Excel be installed on
>> the machine running the program. For each row of the spreadsheet, the
>> first
>> column is the drive letter (without the colon), the second column is the
>> unc
>> path to be mapped to the drive.
>> ====================
>> ' Specify Excel spreadsheet.
>> strExcelPath = "\\MyServer\MyShare\Drives.xls"
>>
>> ' Setup Excel object.
>> Set objExcel = CreateObject("Excel.Application")
>>
>> ' Open specified spreadsheet and select the first worksheet.
>> objExcel.WorkBooks.Open strExcelPath
>> Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
>>
>> ' Read each row of the spreadsheet until a blank is found
>> ' in the first column. Start with row 1.
>> intRow = 1
>> Do While objSheet.Cells(intRow, 1).Value ""
>> strDrive = objSheet.Cells(intRow, 1).Value
>> strPath = objSheet.Cells(intRow, 2).Value
>> Mapit strDrive, strPath
>> intRow = intRow + 1
>> Loop
>>
>> ' Close workbook and quit Excel.
>> objExcel.ActiveWorkbook.Close
>> objExcel.Application.Quit
>>
>> ' Clean up.
>> Set objExcel = Nothing
>> Set objSheet = Nothing
>> ==================
>>
>> Also, your subroutine can be made more efficient by binding to the
>> wshShell
>> and wshNetwork objects elsewhere with global or module level scope. Your
>> subroutine maps to these objects repeatedly for each drive letter to be
>> mapped. (Actually, objShell is not used, so this can be removed.) Also,
>> you
>> enumerate all drives repeatedly for each drive letter. I would attempt to
>> map the drive and trap the error if it cannot be mapped, then remove the
>> mapping. For example:
>>
>> ' Bind to wshNetwork object at module level.
>> Set m_objNetwork = CreateObject("Wscript.Network")
>>
>> Sub Mapit(strLetter, strPath)
>> 'Define whether the map info should be removed from the current
>> user's
>> profile
>> bForceRemoveFromProfile = True
>> bRemovefromprofile = True
>>
>> 'Define wheter the map info should be stored in the current user's
>> profile
>> bStoreinProfile = True
>>
>> 'Define the DriveLetter:
>> DriveLetter = strLetter & ":"
>>
>> 'Define the remote path
>> Remotepath = strPath
>>
>> ' Attempt to map drive. Trap error if drive letter already mapped.
>> On Error Resume Next
>> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
>> If (Err.Number 0) Then
>> On Error GoTo 0
>> ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
>> bForceRemoveFromProfile
>> ObjNetwork.MapNetworkDrive DriveLetter, RemotePath,
>> bStoreInProfile
>> End If
>> On Error GoTo 0
>>
>> End Sub
>>
>> However, you subroutine should work fine, so the above is a minor point.
>> I
>> see no need for the pause in the subroutine. I cannot recall any cases
>> where
>> such a pause has been needed.
>>
>> --
>> Richard
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>>
>> "joeroc" wrote in message
>> @microsoft.com...
>> > The following script allows me to remap network drives that are aleady
>> > in
>> > use. I however would like to pull the drives and share info from an
>> > excel
>> > spreadsheet instead of having to edit the vb file itself. Can anyone
>> > get
>> > me
>> > started on this as I'm eager to learn and am a scripting newbie.
>> >
>> > 'DEFINE DRIVES TO MAP:
>> > '________________________________________________________
>> >
>> > Mapit "V", "\\nycfinmf1\apps"
>> > Mapit "W", "\\nycfinmf1\apps"
>> > '_________________________________________________________
>> > 'SUb
>> > '_________________________________________________________
>> >
>> > Sub Mapit(strLetter, strPath)
>> >
>> > 'Slight puase to ensure each pass has time to commit:
>> > wscript.sleep 200
>> >
>> > 'Define whether the map infor should be removed from the current user's
>> > profile
>> > bForceRemoveFromProfile = True
>> > bRemovefromprofile = True
>> >
>> > 'Define wheter the map info should be stored in the current user's
>> > profile
>> > bStoreinProfile = True
>> >
>> > Set objShell = CreateObject("WScript.Shell")
>> > Set objNetwork = CreateObject("WScript.Network")
>> > Set oDrives = ObjNetwork.EnumNetworkDrives()
>> >
>> > 'Define the DriveLetter:
>> > DriveLetter = strLetter & ":"
>> >
>> > 'Define the remote path
>> > Remotepath = strPath
>> >
>> > 'Check if already connected:
>> > AlreadyConnected = False
>> > For i = 0 to oDrives.Count - 1 step 2
>> > if LCase(oDrives.Item(i)) = LCase(DriveLetter) Then AlreadyConnected =
>> > True
>> > Next
>> >
>> > 'Attempt to map the drive. If already mapped, first attempt to
>> > disconnect
>> > If AlreadyConnected = True Then
>> > ObjNetwork.RemoveNetworkDrive DriveLetter, bRemoveFromProfile,
>> > bForceRemoveFromProfile
>> > ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
>> > Else
>> > ObjNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
>> > End If
>> > End Sub
>> > Wscript.Quit
>>
>>
>>

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Freezing cells in Excel Hello all I have a question that I can't find the answer to concerning freezing cells in Excel from my VB6 app. My app exports a sizable chunk of data to an Excel spreadsheet, (Excel 2003 and 2002). As the datasheet is quite large, I want to freeze the co

Export to Excel and format the cells to be specific data typ Hi all I have searched all over to do this but cannot find it so .... What i am doing is im creating a custom Excel Spreadsheet from a load of data i have which is stored into an array. I can write the spread sheet etc and it all looks good except for one

Visual Basic Excel Reading in Comma Delimited Text Files I am new to VBA- specifically in excel. I am able to open file, read file, and close file. Each line read has several “cells” of data. However, the testfile.txt is comma delimited. Basically, I have a database.txt file which contains information that I

naming range of cells and moving from another book I am currently trying to copy cells from one book to a new workbook. I then name that group of cells in the new workbook. This is repeated multiple times. This would work for me if the copying and pasting was to remain the same, but this is not the case.

Type Mismatch on RangeObj and Cells.Find When Cells.find is null the script returns an error 91 (stops dead). According to some MS help I found at the URL below I should be able to use Set RangeObj = Cells.Find (...) in order to evaluate the result. However I always get a Type mismatch. The Ce
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group