View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Steve Yandl Steve Yandl is offline
external usenet poster
 
Posts: 284
Default How do I Run Macro on Opening if user is not the "Last Saved B

Mike,

On my home computers, there is no difference between the two options.
However, suppose you have Excel installed on a PC that is used by multiple
users who each log in under their own ID. In that case, Option B is going
to reveal the name of the user currently logged in. Option A will show the
name of the person that was entered as the user when Excel was installed on
that PC which may or may not be the currently logged on user.

The "WScript.Network" object is familiar to those who work with scripts
running under the Windows Script Host, typically system administrators
creating vbs files to manage PCs on a network. Along with "Wscript.Shell",
"Scripting.FileSystemObject" and "Scripting.Dictionary" it provides a small
set of tools not built in to VBA.

Steve


"MikeZz" wrote in message
...
Hi Steve, Thanks for the help...

But what's difference between A & B?
Also, never heard of Wscript.Network but googled it....
Is there any benefit to using either of the following?

A: strUser = Application.UserName

B: Set objNetwork = CreateObject("Wscript.Network")
B: strUser = objNetwork.UserName
B: Set objNetwork = Nothing


"Steve Yandl" wrote:

Gary's Student,

I was just doing some testing of this while you were posting. Your line
for
ActiveWorkbook.BuiltInDocumentProperties(7) works fine to retrieve the
Last
Author (last saved by) but item(3) to retrieve 'Author' came up null for
me
until the workbook was saved.

I think it might work better to use
strUser = Application.UserName
to get the name of the user registered for the Excel application used to
open the workbook, or
_________________
Set objNetwork = CreateObject("Wscript.Network")
strUser = objNetwork.UserName
Set objNetwork = Nothing
__________________
if you want the currently logged on user.

Steve



"Gary''s Student" wrote in
message
...
If you have a Workbook Open Event macro, include lines like:

i = ActiveWorkbook.BuiltinDocumentProperties(3)
j = ActiveWorkbook.BuiltinDocumentProperties(7)
If i = j Then
Else
'run your first time code
End If
--
Gary''s Student - gsnu200745


"MikeZz" wrote:

Subject says it all.

Basically, I want to run a macro that applies various filters if a new
user
opens the file. If it's the same user that saved the file before, I
assume
they don't want the view to change.

Thanks,

MikeZz