ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] VBA¸ô®|¸Ì­±­Y¦³ÅܼơA¦p¦ó§ï¦Û°Ê§ì?

[µo°Ý] VBA¸ô®|¸Ì­±­Y¦³ÅܼơA¦p¦ó§ï¦Û°Ê§ì?

¦p¤U­±VBA¡A¦³¨S¦³¿ìªkÅý§Úªº¸ô®|¸Ì­±ªº¹q¸£µn¤JªÌ¦Û°Ê§ì¡A¤£µM¨C¦¸µn¤JªÌ¤£¦P³£­n°»¿ù¥h§ï¸ô®|¦WºÙ¡A¦³¨D±M®a¤F¡AÁÂÁÂ


Private Sub Workbook_Open()
Workbooks.Open Filename:="C:\Users\¹q¸£µn¤JªÌ\Desktop\TEST\TEST.xlsm"
Application.EnableEvents = False
'Workbooks("TEST.xlsm").Close SaveChanges:=False
Application.EnableEvents = True
ThisWorkbook.Close
End Sub

¸ê®ÆÀÉ, ¾¨¶q©ñd¼Ñ, ¦A«Ø±¶®|¨ì®à­±,
¤@¯ë³£·|ÁקKª½±µ¦b®à­±©ñ¸ê®ÆÀÉ~~

TOP

¦^´_ 2# ­ã´£³¡ªL


  ÁÂÁ²a¤j¦^´_¡A§Ú¸ê®ÆÀɦ³¥t¥~©ñ¨ä¥L¸ô®|¡A®à­±ªº¬Ouserªº¨Ï¥ÎÀÉ¡A
¦ý¥Ñ©óuser³£·|§â¨Ï¥ÎÀɧì¤U¨Ó©ñ®à­±,©Ò¥H¤~·Q»¡¦³³o»Ý¨D for ¦]À³user¤£¦P¨ÓÅܰʸô®|

TOP

¦^´_ 3# RCRG

Option Explicit '«Å§iGetUserName Function
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Sub Get_User_Name()
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
Debug.Print UserName
End Sub

³o¬qµ{¦¡¥i¥H§ì¥XWindowsµn¤JªÌ±b¸¹(UserName),½Ð¨Ì»Ý¨D¦Û¦æ­×§ï

TOP

¦^´_ 4# jcchiang

ÁÂÁ¤j¤j¦^´_,§Ú¬O¤]¦³¬q¥i¥H§ìµn¤J±b¸¹ªºµ{¦¡(§ìµn¤JªÌ¨Ã¶ñ¦b¬YÄæ¦ì),¥i¬O§Ú¤£ª¾¹D«ç¼Ë§â¥L¸ò§Úªº¸ô®|µ²¦X¦b¤@°_...XD

TOP

¦^´_ 5# RCRG

"C:\Users\" + UserName + "\Desktop\TEST\TEST.xlsm"

TOP

¦^´_ 6# jcchiang


    ­ì¨Ó¬O¥Î + µ²¦X¡A§Ú¤@ª½¥Î&
ÁÂÁ¤j¤j¡A¤w¸Ñ¡C

TOP

¥»©«³Ì«á¥Ñ ­ã´£³¡ªL ©ó 2020-1-16 15:44 ½s¿è

¨S´ú. ¤£ª¾¦æ¤£¦æ??
Tr = Split(Environ("USERPROFILE"), "\")
Workbooks.Open Filename:="C:\Users\" & Tr(UBound(Tr)) & "\Desktop\TEST\TEST.xlsm"

©ÎªÌ§ï
Tr = Split(Environ("HomePath"), "\")

©Î
Workbooks.Open Filename:="C:\Users\" & Environ("USERNAME") & "\Desktop\TEST\TEST.xlsm"


====================

TOP

        ÀR«ä¦Û¦b : ¯à·F¤£·F¡A¤£¦p­W·F¹ê·F¡C
ªð¦^¦Cªí ¤W¤@¥DÃD