我有這個代碼,創建一個文件夾和一個實際的文件保存在它,但我希望它只保存一份副本只有一張它。這樣代碼文件就像一個模板...創建文件夾和新的* .xlsx文件與模板,如xlsm文件中的宏
你寫你的東西,然後按下按鈕,它會在一個新的創建文件夾中保存一個.xlsx文件(一張表格)。 。所以你可以用數百個文件夾來做到這一點。
那麼到底應該像這樣工作:
- 您打開.XLSM文件,其中下面的代碼是
- 你得張一種形式(什麼應該被「出口」後。上)和 一個列表,你在表格中複製東西。
- 填寫完表格並按下按鈕後,它會將表格 工作表保存爲新文件夾中的.xlsx,您可以繼續使用.xlsm 文件。
如果你不清楚,請詢問。
的代碼,我現在在這裏
Sub Macro1()
Dim strFilename, strDirname, strPathname, strDefpath As String
On Error Resume Next ' If directory exist goto next line
strDirname = Range("D81").Value ' New directory name
strFilename = Range("D8").Value 'New file name
strDefpath = Application.ActiveWorkbook.Path 'Default path name
If IsEmpty(strDirname) Then Exit Sub
If IsEmpty(strFilename) Then Exit Sub
MkDir strDefpath & "\" & strDirname
strPathname = strDefpath & "\" & strDirname & "\" & strFilename 'create total string
ActiveWorkbook.SaveAs Filename:=strPathname & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
問題是我對於那些像1102,1103的事情一樣,這些表格的名稱。下一步是,有一個名爲1102_1和1102_2文件,他們都應該在文件夾1102去...
這是一個有點出我knownledge的請幫我傢伙:)迎接
現在我我使用下面的代碼 問題是,它總是關閉xlsm
文件什麼真的煩人,當我重新打開它想要更新文件,我需要刪除,但我不知道如何:/ ...它只應該導出/保存一張特殊紙張
Private Sub CommandButton1_Click()
Dim strFilename As String, _
strDirname As String, _
strPathname As String, _
strDefpath As String, _
SheetToExport As String, _
WbMaster As Workbook, _
WbCopy As Workbook
On Error Resume Next ' If directory exist goto next line
strDirname = Range("W12").Value ' New directory name
strFilename = Range("D8").Value 'New file name
Set WbMaster = Application.ActiveWorkbook
SheetToExport = Range("A1").Value 'Or specify UserForm output
strDefpath = WbMaster.Path 'Default path name
If IsEmpty(strDirname) Then Exit Sub
If IsEmpty(strFilename) Then Exit Sub
MkDir strDefpath & "\" & strDirname
strPathname = strDefpath & "\" & strDirname & "\" & strFilename 'create total string
WbMaster.Sheets(SheetToExport).Copy
Set WbCopy = Application.ActiveWorkbook
WbCopy.SaveAs Filename:=strPathname & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
WbCopy.Close
End Sub
呦可以用一個XLSM文件多達XLSX文件創建,如你所願。然而,將宏保存在新的XLSX中是不可能的。 – Balinti
@Balinti:我沒有看到Swi要求解決方案,將宏保存在XLSX文件中。但是我對他/她想要的東西也有點朦朧。標題是'.xls',它表示應該創建舊的Excel文件格式。同時代碼建議將新工作簿保存爲'.xlsm'。那麼,現在是什麼? – Ralph
@Balinti你有什麼想法我可以阻止它從關閉本身? – Swi