다른 사용자가 내 추가 기능을 실행할 때 동일한 코드를 직접 실행해도 문제가 없는데 범위 밖의 첨자가 나타납니다. 이 문제는 통합 문서 값을 설정할 때 발생합니다. 파일 이름은 현재 날짜를 가져 와서 생성되고 gendate로 저장됩니다. 이 파일 이름은 사용자가 만든 파일 경로를 기반으로 만들어지고 저장됩니다. 이 예에서 gv.Range ("b2"). text 값은 C : \ Users \ username \ Desktop \ ReportGeneration입니다. 따라서 fp는 C : \ Users \ dmulhausen \ Desktop \ ReportGeneration \ TSReports9_6_201615h5m32s.xlsx 입니다.이 스크립트는 나를 위해 오류를 생성하지는 않지만 스크립트의 다른 사용자에게 오류를 생성합니다.아래 첨자가 범위를 벗어남 오류 9 vba
Dim ai As Workbook 'add in data ---Initialized in Report Setup
Dim dwb As Workbook 'destination workbook ---Initialized in Report Setup
Dim ss As Worksheet 'source sheet
Dim ds As Worksheet 'destination sheet or writing sheet
Dim rv As Worksheet 'reporting variables sheet ---Initialized in Report Setup
Dim pv As Worksheet 'ts variables sheet ---Initialized in Report Setup
Dim gv As Worksheet 'global ai variables ---Initialized in Report Setup
Dim tempstr As String
Dim fp As String 'file path ---Initialized in Report Setup
Dim gendate As Date
Dim reportscreated As Integer
Dim initialized As Boolean
Dim sheetnames(1 To 12) As String
Sub reportsetup()
Set ai = Workbooks("TSReports add in.xlam")
Set rv = ai.Worksheets("ReportVars")
Set pv = ai.Worksheets("TS1_2Vars")
Set gv = ai.Worksheets("globalVars")
If (IsEmpty(gv.Range("b2").Value)) Then
MsgBox ("Please select a designated folder for reports")
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
gv.Range("b2").Value = .SelectedItems(1)
End If
ai.Save
End With
End If
initialized = True
gendate = Now()
tempstr = "TSReports" & Month(gendate) & "_" & Day(gendate) & "_" & Year(gendate) & Hour(gendate) & "h" & Minute(gendate) & "m" & Second(gendate) & "s"
fp = gv.Range("b2").Text & "\" & tempstr & ".xlsx"
Workbooks.Add
Application.DisplayAlerts = False
Application.AlertBeforeOverwriting = False
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=fp
Set dwb = Workbooks(tempstr) '*******Error occurs here*******