2016-08-18 248 views
-1

,以便將日期放入我創建的工作簿中。我使用此代碼。Vba無法識別變量文件名

Dim tarih As String 
Dim dot As String 
dot = "." 

Dim days2 As Integer 
Dim months2 As Integer 
Dim years2 As Integer 
days2 = Day(Date) 
months2 = Month(Date) 
years2 = Year(Date) 

tarih = days2 & dot & months2 & dot & years2 

Workbooks.Add 

ActiveWorkbook.SaveAs "C:\Users\" & Environ$("USERNAME") & "\Desktop\Excel Before Code Templates (BCT)\ROL_Analysis" & tarih & ".xlsx" 
Application.WindowState = xlMinimized 

Dim strii As String 
strii = "ROL_Analysis" & tarih & ".xlsx" 

Workbooks("ROL_Analysis" & tarih & ".xlsx").Activate 

我直接使用名稱,之後我定義了一個字符串來放它,但它不起作用。有任何想法嗎?

+0

你得到一個錯誤?什麼線? –

回答

0
Workbooks.Add 

Dim strii As String 
strii = "ROL_Analysis" & tarih & ".xlsx" 

ActiveWorkbook.SaveAs "C:\Users\" & Environ$("USERNAME") & "\Desktop\Excel Before Code Templates (BCT)\" & strii & "" 
Application.WindowState = xlMinimized 

Workbooks(strii).Activate 

確定這個工程