vba将xltm文件另存为xlsb文件

时间:2019-02-15 12:37:14

标签: excel vba save-as xlsb

我有一个脚本,该脚本打开一个外部文件来执行脚本,并在完成脚本后将其另存为xlsb文件。该代码非常适合将文件从xlsb保存到xlsb。但是因为我想对原始文件具有一定的安全性,所以我希望原始xlsb文件是xltm文件。我将“另存为”脚本进行了调整,并在文件本身中将其作为单独的例程进行了测试。它运作完美。

现在,我将例程添加到了外部脚本文件中,但是当我执行脚本时,Excel冻结并且根本没有“另存为”屏幕。 我希望外部脚本具有其他一些外部引用可以正常工作,但是我无法弄清楚如何对此进行调整。

这是原始文件的代码

Option Explicit
Sub vernieuwalles()
Dim myTemplate As String: myTemplate = ActiveWorkbook.Name
Dim myTool As String: myTool = "refresh_segment_template.xlsm"

  Application.ScreenUpdating = False

  Workbooks.Open GetPath & myTool
  Application.Run myTool & "!vernieuwalles", myTemplate

  Call Windows(myTool).Close(False)

  Application.ScreenUpdating = True

End Sub
Private Function GetPath() As String
Dim myPosition As Integer
Dim myPath As String: myPath = ActiveWorkbook.Path

  myPosition = InStr(StrReverse(myPath), "\") - 1
  myPosition = Len(myPath) - myPosition

  GetPath = Mid(myPath, 1, myPosition - 1) & "\XLAM\"

End Function

它是指要打开并执行的外部脚本文件。

外部文件具有以下脚本(我仅将保存内容粘贴为脚本的一部分):

Option Explicit

Dim aantalrijen As Long

Const SheetSchaduwblad As String = "schaduwblad"
Sub vernieuwalles(mytemplate As String)

  Windows(mytemplate).Activate

  On Error GoTo Err_

  Application.StatusBar = "Bezig met vernieuwen"

  Application.ScreenUpdating = False
  Application.Calculation = xlCalculationManual

'  Call SheetOpschonen

  Call datawissen
  Call dataplaatsen
  Call kolomtitels
  Call toevoegen
  Call maaktabel
  Call refreshpivots

Exit_:
  Application.StatusBar = ""
  Application.ScreenUpdating = True
  Application.Calculation = xlCalculationAutomatic
  Exit Sub

Err_:
  Call MsgBox(Err.Number & vbCrLf & Err.Description)
  Resume Exit_

Application.Calculation = xlCalculationAutomatic

End Sub

Sub refreshpivots()
Dim workbook_Name As Variant
Dim location As String
Dim workbookdirectory As String
Dim activewb As String

ActiveWorkbook.RefreshAll

activewb = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5)

workbookdirectory = "M:\Commercie\Marktdata\IRi\Segment Ontwikkeling\"

workbook_Name = Application.GetSaveAsFilename(fileFilter:="Excel binary sheet (*.xlsb), *.xlsb", InitialFileName:=workbookdirectory & activewb)

If workbook_Name = False Then

ActiveWorkbook.SaveAs filename:=activewb, FileFormat:=50

End If

但是,当我从原始文件执行脚本时,excel会如所指出的那样冻结。要使此代码与外部文件一起使用以及将文件从xltm保存到xlsb脚本,应该进行哪些更改?

如所指出的:另存为脚本是唯一在脚本中更改的内容,而xlsb到xltm扩展名更改是原始文件中唯一的更改

0 个答案:

没有答案