Copying files to other systems

chandrashekar

Well-known Member
Joined
Jul 15, 2005
Messages
529
Office Version
  1. 365
Platform
  1. Windows
Hi,

How to copy files to other systems which is password protected using vba.

Thanks,

Chandra Shekar
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
What other systems? How are they connected to the machine on which the files are currently located? In what way are these other systems "password protected using vba"?
 
Upvote 0
Hi,

We are using LAN Network. We have given our own password to system which can be shared between us. I am trying to copy source file to all system (30 Nos) at one shot.

Thanks,

Chandra Shekar B
 
Upvote 0
You can't copy a file to more than one system at a time - if you have thirty remote systems you would have to issue thirty separate copy commands.

In VBA this is done using FileCopy: see http://www.rondebruin.nl/folder.htm.

To connect to the remote systems and disconnect from them again, you could use the following MapDrive and UnMapDrive functions:-
Code:
[FONT=Fixedsys]Option Explicit[/FONT]
 
[FONT=Fixedsys]Private Const CONNECT_UPDATE_PROFILE = &H1[/FONT]
[FONT=Fixedsys]Private Const RESOURCE_CONNECTED As Long = &H1&
Private Const RESOURCE_GLOBALNET As Long = &H2&
Private Const RESOURCETYPE_DISK As Long = &H1&
Private Const RESOURCEDISPLAYTYPE_SHARE& = &H3
Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1&[/FONT]
[FONT=Fixedsys]Private Declare Function WNetCancelConnection2 Lib "mpr.dll" _
  Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long[/FONT]
[FONT=Fixedsys]Private Declare Function WNetAddConnection2 Lib "mpr.dll" _
  Alias "WNetAddConnection2A" (lpNetResource As NETCONNECT, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]Private Type NETCONNECT
  dwScope As Long
  dwType As Long
  dwDisplayType As Long
  dwUsage As Long
  lpLocalName As String
  lpRemoteName As String
  lpComment As String
  lpProvider As String
End Type[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]Public Function MapDrive(LocalDrive As String, RemoteDrive As String, _
  Optional Username As String, Optional Password As String) As Boolean[/FONT]
[FONT=Fixedsys][COLOR=green][/COLOR][/FONT] 
[FONT=Fixedsys][COLOR=green]' Usage: MapDrive "Q:", "[/COLOR][/FONT][URL="file://\\RemoteMachine\RemoteDirectory"][FONT=Fixedsys][COLOR=green]\\RemoteMachine\RemoteDirectory[/COLOR][/FONT][/URL][FONT=Fixedsys][COLOR=green]", "MyLoginName", "MyPassword"[/COLOR][/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]  Dim NetR As NETCONNECT[/FONT]
[FONT=Fixedsys]  NetR.dwScope = RESOURCE_GLOBALNET
  NetR.dwType = RESOURCETYPE_DISK
  NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
  NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
  NetR.lpLocalName = Left(LocalDrive, 1) & ":"
  NetR.lpRemoteName = RemoteDrive[/FONT]
[FONT=Fixedsys]  MapDrive = (WNetAddConnection2(NetR, Username, Password, CONNECT_UPDATE_PROFILE) = 0)
    
End Function[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]Public Function UnMapDrive(LocalDrive As String) As Boolean[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys][COLOR=green]' Usage: UnMapDrive "Q:"[/COLOR][/FONT]
[FONT=Fixedsys][COLOR=#008000][/COLOR][/FONT] 
[FONT=Fixedsys]  Dim NetR As NETCONNECT[/FONT]
[FONT=Fixedsys]  NetR.dwScope = RESOURCE_GLOBALNET
  NetR.dwType = RESOURCETYPE_DISK
  NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
  NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
  NetR.lpLocalName = Left(LocalDrive, 1) & ":"
  NetR.lpRemoteName = ""[/FONT]
[FONT=Fixedsys]  UnMapDrive = (WNetCancelConnection2(LocalDrive, CONNECT_UPDATE_PROFILE, False) = 0)[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]End Function[/FONT]
Place this code in a new general code module
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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