PDA

View Full Version : Supply Windows Username and Password via VBA



gnaga
05-24-2011, 01:54 PM
My current macro is running in one of the network PC with User-A login. When I execute the follwoing line, I get an error as User-A is not having access to view this file.

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.Getfile("//XXXXX/XXXXX/ABC.xlsm")
Set SrcBook = Workbooks.Open(f)

Just before executing this code, can we change windows logon Username and password to another user say User-B who has the access to this file?

Finally I would like to revert back to User-A logon.
__________________
Regards
GNaga

Kenneth Hobs
05-25-2011, 05:29 AM
By forum rules, password questions can not be asked nor answered.

What I can tell you is that Excel workbooks do not ask or use a window's username unless specifically coded to do so. So, yes, I could give you code to change the username but by rule, I can not do so. The designer of the program has designed it so that you must be a valid user to use it. We have no way to know that.

In your code, just put the string name for the workbook in the open, there is no reason for fso. Of course workbooks.open allows you to send a password to open it.