在这段VBA代码中使用EOMONTH时遇到一些麻烦:
'Create a new file that will receive the data
Set newWB = Workbooks.Add
With newWB
Set newS = newWB.Sheets("Sheet1")
newS.Range("A1").PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
'Save in CSV
Dim PathDate As String
Dim SavePath As String
Dim SaveAs As String
Dim FileName As String
Dim sDate As String
'// File path date
PathDate = Format(Range("D1"), 0), "MMDDYYYY")
'// Save it Path
SavePath = "C:\User"
'// Format the on "D1" to MMDDYYYY
sDate = Format(currentWB.Sheets("Upload sheet").Range("D1"), "MM.DD.YYYY")
'// File Name
FileName = "NewFileName"
'// Save with File Name & Date & .CSV
SaveAs = SavePath & "\" & FileName & "-" & sDate & ".csv"
.SaveAs FileName:=SaveAs
Application.DisplayAlerts = True
End With
我要做的就是得到= EOMONTH(D1,0)会得到的相同结果,而不是S2所在的位置。
答案 0 :(得分:0)
类似
PathDate = Format(currentWB.Sheets("Upload sheet").Range(Application.WorksheetFunction.EoMonth(Range("D1").value, 0)), "MMDDYYYY")
您说的是S2。我想知道这是否有点字面意思,你是说
With currentWB.Sheets("Upload sheet")
PathDate = Format(Application.WorksheetFunction.EoMonth(.Range("D1").value, 0),"MMDDYYYY")
End With