打开另一个Excel工作簿-自动计算

时间:2018-07-30 13:11:04

标签: excel vba excel-vba

在我的主要excel文件之一中,有一个vba代码,可用来从其他文件调用其他excel工作表。 由于我的主文件开始变慢,我想在Workbook模块中添加一个简单的代码,以使其通过“ CalculationManual”打开,然后通过“ CalculationAutomatic”将其关闭,一切正常。

但是,当我尝试从其他文件中调用其他工作表时,在vba中,它首先将自动化更改为“自动”,但是没有打开所选的工作簿,并且在出现错误之后,我看到计算再次在“手动”进行。

这是工作簿中的代码;

Sub Workbook_BeforeClose(Cancel As Boolean)
Call Dijital_Off
    Application.CellDragAndDrop = True
    Application.Calculation = xlCalculationAutomatic
End Sub
Sub Workbook_Open()
Worksheets("Acilis").Activate
Worksheets("Acilis").Range("A1").Select
    Application.CellDragAndDrop = True
Worksheets("Acilis").ScrollArea = "A1:B2"
Application.Calculation = xlCalculationManual
End Sub

这是我用来调用其他工作簿的代码的开头;

    Sub Storyboard_Ekle()

    Application.Calculation = xlCalculationAutomatic

    Worksheets("Egitim Bilgileri").Unprotect Password:="**$#Bildircin'A1313XQ.;**"
    Worksheets("Egitim Bilgileri").Visible = True
    Worksheets("Kunye").Unprotect Password:="**$#Bildircin'A1313XQ.;**"
    Worksheets("Acilis").Visible = True
    Worksheets("Yonetim").Unprotect Password:="**$#Bildircin'A1313XQ.;**"

        Dim DosyaSec As Office.FileDialog

        Set DosyaSec = Application.FileDialog(msoFileDialogFilePicker)

       With DosyaSec

          .AllowMultiSelect = False
          .Title = "Lütfen yeni eklenecek Storyboard dosyasini seçiniz."
          .Filters.Clear
          .Filters.Add "Excel Macro-Enabled Workbook", "*.xlsm"
          .Filters.Add "Excel Workbook", "*.xlsx"
          .Filters.Add "All Files", "*.*"

          If .Show = True Then
            YeniSB = .SelectedItems(1)
            Else: GoTo Son
          End If

    Dim YeniStoryBoard As Workbook
    Dim AnaDosya As Workbook
    Dim YeniStoryBoard_Sheet As Worksheet
    Dim AnaDosya_Sheet As Worksheet

    Application.ScreenUpdating = False

    Set AnaDosya = ThisWorkbook
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    Application.AskToUpdateLinks = False


    Dim Yeni_Sheet As String

Set YeniStoryBoard = Workbooks.Open(YeniSB)

YeniStoryBoard.Worksheets("Storyboard").Visible = True
YeniStoryBoard.Worksheets("Storyboard").Unprotect Password:="**$#Bildircin'A1313XQ.;**"

ThisWorkbook.Worksheets("Kunye").Visible = True
YeniStoryBoard.Worksheets("Storyboard").Copy After:=ThisWorkbook.Worksheets("Kunye")

我得到:

  

“运行时错误1004,对象'工作簿'的方法'打开'失败”错误

由于在实现自动化时代码没有打开YeniSB故事板,因此在Set YeniStoryboard = Workbooks.Open(YeniSB)处出现错误。

0 个答案:

没有答案