嗨,我有一些代码似乎在家里的PC上工作得很好,但是一旦我在Work中尝试它们,它们似乎不起作用。真奇怪。有什么想法吗?
脚本的想法是
我知道这看起来很奇怪,但它适用于某些但不适用于其他人,这有什么理由吗? 我得到的错误是
运行时错误'1004':无法访问该文件。试试其中之一 以下:
使指定的文件夹存在。
确保包含该文件的文件夹不是只读的。
确保文件名不包含以下任何字符:< > ? []:|或*
确保文件/路径名称不超过218个字符。
欢迎任何帮助。我的代码是
Sub save_as_xlsm_and_XML()
Dim filename
Dim XML_Name_Complete
Dim XLSM_Name
Dim Temp_Name
Dim fldr As FileDialog
Dim sItem As String
Dim Last_Column As Long
filename = ActiveWorkbook.Name
Temp_Name = InputBox("Enw Dosbarth")
If Temp_Name = "" Then Exit Sub
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
XLSM_Name = sItem & "\" & Temp_Name
XML_Name_Complete = sItem & "\" & Temp_Name & "-lanlwythiad"
Application.ScreenUpdating = False ' turn off the screen updating
'Moving data from final_before_copy to adroddiad
Sheets("Final_Before_Copy").Select
Rows("8:250").Select
Selection.Copy
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
Sheets("adroddiad").Select
Rows("8:8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Rows("1:4").EntireRow.Hidden = True
' Arbed fel XML '
Cells.Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayHeadings = False
Range("a1").Select
ActiveSheet.Name = "Adroddiad"
Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Sheet3").Select
ActiveWindow.SelectedSheets.Delete
ChDir sItem
ActiveWorkbook.SaveAs filename:=XML_Name_Complete _
, FileFormat:=xlXMLSpreadsheet, CreateBackup:=True
If XML_Name_Complete = False Then Exit Sub
Application.DisplayAlerts = False
ActiveWorkbook.Close True
'Arbed fel xlsm'
ThisWorkbook.Activate
Sheets("Marciau").Select
Range("A6").Select
ChDir sItem
ActiveWorkbook.SaveAs filename:=XLSM_Name _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Application.DisplayAlerts = False
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"",False)"
Application.ScreenUpdating = True ' turn on the screen updating
successful_export = MsgBox("Adroddiad wedi ei arbed ac allforio yn lwyddiannus", , "System Adroddiadau")
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Sub