saveas calling a variable

  • Thread starter Thread starter Douvid
  • Start date Start date
D

Douvid

HI,
I need to use an inputbox to get the user name of the user
and then save the workbook to a specific location. This
location where I need to reinsert the user name as a
variable. I try this but something is wrong with the
argument. I haven't succeed to writte the synthaxe to
insert my variable in the location.
Thanks for your advices
Application.ThisWorkbook.SaveAs D:\The Documents and
Settings/<user name>/Application Data/Microsoft/AddIns
 
Douvid,
try

ThisWorkbook.SaveAs "D:\The Documents and Settings/" & <user name> &
"/Application Data/Microsoft/AddIns"

watch for wrap-around.
 
ok bob and how do I have to declare the variable that
will insert the user name ? this causes me problems
 
Hi Bob,
this is the procedure I'm using but I always get error
message or about the oject or about something else, can
you help on that one. thanks a lot
douvid

Sub installmytooloading()
Dim qst
Dim user

user = InputBox("Please enter your username for this
computer", "UserName")
ThisWorkbook.SaveAs "D:\The Documents and Settings/" &
user.Value & "/Application Data/Microsoft/AddIns"

End Sub
 
Douvid,

You do not use user.Value, as user is a variable not an object with a Value
property. Just use

user = InputBox("Please enter your username for this computer", "UserName")
ThisWorkbook.SaveAs "D:\The Documents and Settings/" & user & _
"/Application Data/Microsoft/AddIns"

You can also get the user automatically (I am assuming you have XP, or
Win2000?). This function returns it
Public Declare Function GetUserName Lib "advapi32.dll" _

Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Public Function UserName() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left$(sName, cChars - 1)
End If
End Function

So you would then use
ThisWorkbook.SaveAs "D:\The Documents and Settings/" & Username & _
"/Application Data/Microsoft/AddIns"
 
Back
Top