如题所述
大家好,告诉你们一个不用引用的一种方法
一个可以获取系统环境变量的系统vb函数
MsgBox Environ("USERPROFILE") & "\桌面"
一个可以获取系统环境变量的系统vb函数
MsgBox Environ("USERPROFILE") & "\桌面"
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2016-01-09
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Private Sub Form_Load()
Dim sBuffer As String
Dim lSize As Long
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
Dim A As String
If lSize > 0 Then
A = Left$(sBuffer, lSize)
A = Left(A, Len(A) - 1)
MsgBox "c:\Documents and settings\" & A & "\桌面\"
Else
A = vbNullString
End If
End Sub本回答被提问者采纳
Private Sub Form_Load()
Dim sBuffer As String
Dim lSize As Long
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
Dim A As String
If lSize > 0 Then
A = Left$(sBuffer, lSize)
A = Left(A, Len(A) - 1)
MsgBox "c:\Documents and settings\" & A & "\桌面\"
Else
A = vbNullString
End If
End Sub本回答被提问者采纳
第2个回答 推荐于2016-04-25
首先在工程的引用中选中Windows Scripting Host Object Model
Private Sub Form_Load()
Dim desk As New WshShell
MsgBox desk.SpecialFolders("desktop")
End Sub
Private Sub Form_Load()
Dim desk As New WshShell
MsgBox desk.SpecialFolders("desktop")
End Sub
第3个回答 2007-10-14
要先在 工程-引用中添加 windows script host object model
Dim kk As New IWshRuntimeLibrary.IWshShell_Class
text1.text= kk.SpecialFolders("Desktop")
Dim kk As New IWshRuntimeLibrary.IWshShell_Class
text1.text= kk.SpecialFolders("Desktop")
第4个回答 2007-10-14
vb我不会,要是单纯想获得桌面路径,在这里
%USERPROFILE%\桌面
%USERPROFILE%\桌面