-1

我遇到编译错误。我试图在这个子程序中简化一些事情,因为我有很多设置,我希望能够从我的 excel 工作表中控制它们需要很多调用,并且正在寻找一种更有效的方式来编写它们。

我尝试将工作簿和工作表分配给变量,然后使用我需要从中提取的工作表的变量来选择我需要的单元格范围,但是第一个实例

Build.Range("B:B").Column.Select.AutoFit

给我无法编译错误“找不到方法或数据成员”

我正在调用 3 个不同的子程序,它们都包含在同一个模块中,如果这对事物有任何影响,并且可以在必要时发布这些子程序,但基本上它们只是根据此子程序提供的设置创建文件并在幻灯片上放置东西

Sub BuildTemplate()
Dim vNewPrimaryTemplatePath As String
Dim vDPI As Integer
Dim WB As Workbook
Dim Settings As Worksheet
Dim Build As Sheets
Dim Entry As Sheets

'Set Global Variables
Set WB = Workbooks("tool.xlsm")             'Set this to the name of the excel file
Set Settings = WB.Sheets("SETTINGS")        'Set this to the name of the settings tab
Set Build = WB.Sheets("BUILD")              'Set this to the name of the build tab
Set Entry = WB.Sheets("ENTRY")              'Set this to the name of the entry tab

    vDPI = Settings.Cells(2, "B").Value

'Adjust column sizes
    Build.Range("B:B").Column.Select.AutoFit
    Build.Range("D:D").Column.Select.AutoFit
    Build.Range("F:F").Column.Select.AutoFit
    Build.Range("H:H").Column.Select.AutoFit

'Create Template Files
MoveFiles
'Open newly created Template File
Dim PPT As PowerPoint.Application
Set PPT = New PowerPoint.Application
    PPT.Visible = True
    PPT.Presentations.Open Filename:=vNewPrimaryTemplatePath
'Add Title Block
Call AddShape(False, "BUILD", Settings.Range("E2"), Settings.Range("E3"),    Settings.Range("E4"), Settings.Range("E5"), Settings.Range("E6"))

'Add Delivery Block
Call AddShape(False, "BUILD", Settings.Range("E9"), Settings.Range("E10"), Settings.Range("E11"), Settings.Range("E12"), Settings.Range("E13"))

'Add Address Block
Call AddShape(False, "BUILD", Settings.Range("E16"), Settings.Range("E17"), Settings.Range("E18"), Settings.Range("E19"), Settings.Range("E20"))

'Add Items
Call AddShape(False, "BUILD", Settings.Range("H2"), Settings.Range("H12"), Settings.Range("H10"), Settings.Range("H16"), Settings.Range("H17"))
Call AddShape(False, "BUILD", Settings.Range("H3"), Settings.Range("H13"), Settings.Range("H10"), Settings.Range("H16"), Settings.Range("H17"))
Call AddShape(False, "BUILD", Settings.Range("H4"), Settings.Range("H14"), Settings.Range("H10"), Settings.Range("H16"), Settings.Range("H17"))
Call AddShape(False, "BUILD", Settings.Range("H5"), Settings.Range("H15"), Settings.Range("H10"), Settings.Range("H16"), Settings.Range("H17"))
Call AddShape(False, "BUILD", Settings.Range("H6"), Settings.Range("H12"), Settings.Range("H11"), Settings.Range("H16"), Settings.Range("H17"))
Call AddShape(False, "BUILD", Settings.Range("H7"), Settings.Range("H13"), Settings.Range("H11"), Settings.Range("H16"), Settings.Range("H17"))
Call AddShape(False, "BUILD", Settings.Range("H8"), Settings.Range("H14"), Settings.Range("H11"), Settings.Range("H16"), Settings.Range("H17"))
Call AddShape(False, "BUILD", Settings.Range("H9"), Settings.Range("H15"), Settings.Range("H11"), Settings.Range("H16"), Settings.Range("H17"))

'Add Summaries
    AddSummary

'Save & Close
    ActivePresentation.SaveAs Filename:=vNewPrimaryTemplatePath, FileFormat:=ppSaveAsDefault
    ActivePresentation.Close

End Sub

再次感谢您的帮助

4

1 回答 1

3

您不需要Select,您可以简化:

Build.Columns(2).AutoFit

但是从另一个角度来看,您错误地定义了变量 Build 和 Entry,它们应该是Worksheet对象而不是Sheets集合。

于 2013-03-23T08:35:17.050 回答