Solved

Username parameter

Posted on 2010-11-10
3
445 Views
Last Modified: 2012-05-10
In the following code I will like to use the username variable instead of the hardcoded  "c:\excelver.dat". So if the username is cis7777, I want the code to open
"c:\cis7777.dat" file.

Help

Thanks
Cheers



option explicit

    Dim oSession        ' AS NotesSession
    Dim strServer
    Dim strUserName
    Dim strMailDbName
    Dim oCurrentMailDb  ' as NOTESDATABASE
    Dim oMailDoc        ' as NOTESDOCUMENT
    Dim ortItem         ' as NOTESRICHTEXTITEM
    Dim ortAttacment    ' as NOTESRICHTEXTITEM
    Dim oEmbedObject    ' as ????
    dim cstrAttachment
    Dim blAttachment

    cstrAttachment = "c:\excelver.dat"

Dim xl, ver, vers
On Error Resume Next
Set xl = CreateObject("Excel.Application")
On Error Goto 0
If xl is Nothing then
      vers = "Microsoft Excel not installed"
Else
      ver = xl.Version
      xl.Quit
      Set xl = Nothing

      Select case Int(left(ver, InStr(ver, ".")-1))
      Case 14   : vers = "Microsoft Excel 2010"
      Case 12   : vers = "Microsoft Excel 2007"
      Case 11   : vers = "Microsoft Excel 2003"
      Case 10   : vers = "Microsoft Excel 2002"
      Case 9    : vers = "Microsoft Excel 2000"
      Case 8    : vers = "Microsoft Excel 97"
      Case 7    : vers = "Microsoft Excel 95"
      Case else : vers = "Microsoft Excel (unknown version)"
      End Select

End If
0
Comment
Question by:Bianchi928
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
KenMcF earned 250 total points
ID: 34108072
You could use something like this

Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
 cstrAttachment = "c:\" & WshNetwork.UserName & ".dat"

0
 

Author Comment

by:Bianchi928
ID: 34108129
That works fine..I have one more little thing to ask....How do I go about checking if the file "c:\" & WshNetwork.UserName & ".dat" exist from a previous run and delete it first it it exists.

Thanks
Cheers
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34108219
Try this

Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
strFile = "c:\" & WshNetwork.UserName & ".dat")
If fso.FileExists(strFile) Then
fso.DeleteFile(strFile)
End If
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now