SaveAs方法错误

时间:2017-11-02 13:46:19

标签: excel excel-vba vba

我不断得到'方法'SaveAS'对象'_Workbook'失败了,我不能为我的生活找出原因。以下代码......欢迎任何与初始问题无关的推荐!

Private Sub CommandButton1_Click()

'Declarations
    'The two workbooks to be involved
    Dim SourceWB As Workbook
    Dim DestinationWB As Workbook

'values to contain cell data to be copied across the worksheet
Dim systemName As Variant
Dim systemID As Variant
'Counter variable to allow for the loop
Dim counter As Integer

'Set the source workbook equal to the current workbook
Set SourceWB = ActiveWorkbook

For counter = 1 To 5

'Set the values for the two data values to be copied
     systemName = SourceWB.Sheets("Sheet1").Cells(counter, 1).Value
     systemID = SourceWB.Sheets("Sheet1").Cells(counter, 2).Value
'Open the destination Workbook
    Set DestinationWB = Workbooks.Open("Path to workbook")
'Set destination cells equal to the copied data from the source sheet
    DestinationWB.Sheets("Questionnaire").Cells(7, 3).Value = systemName
    DestinationWB.Sheets("Questionnaire").Cells(8, 3).Value = systemID
    'Set fname to save Destination Workbook
    Fname = "H:\Desktop\Automated Questionnaires to send\" & systemName & " Applicability Questionnaire.xlsm"
'Save the Destination workbook
    DestinationWB.SaveAs Filename:=Fname, FileFormat:=52
    DestinationWB.Close    
Next counter


End Sub

0 个答案:

没有答案
相关问题