我无法编译错误。我试图简化这个子程序中的一些东西,因为我有很多设置,我希望能够从我的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
再次感谢您的帮助
答案 0 :(得分:3)
您不需要选择,您可以简化:
Build.Columns(2).AutoFit
但是在第二种观点中,你错误地定义了变量Build和Entry,它们应该是Worksheet
个对象,而不是Sheets
个集合。