tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,913
- Office Version
- 365
- 2019
- Platform
- Windows
My workbook contains a single worksheet with data in cells A1 to A3.
This code reads the data into an array:
The problem occurs if the above Sub is saved in the Workbook_BeforeSave event.
So I have:
This is Module1:
When I try to save the workbook, the program crashes on this line:
Can someone tell me what is wrong?
It seems the program cannot "see" the data and read it into MyArray.
Thanks
This code reads the data into an array:
Code:
Dim MyArray() As Variant
MyArray() = Sheet1.Cells(1, 1).CurrentRegion.Value
The problem occurs if the above Sub is saved in the Workbook_BeforeSave event.
So I have:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim MyArray() As Variant
MyArray() = Sheet1.Cells(1, 1).CurrentRegion.Value
End Sub
This is Module1:
Code:
Option Explicit
Sub S()
Dim FileSelector As FileDialog
Set FileSelector = Application.FileDialog(fileDialogType:=msoFileDialogSaveAs)
With FileSelector
.FilterIndex = 1
.InitialFileName = ThisWorkbook.Path & "\"
.Title = "Please Type A Filename"
Dim FileSelected As Boolean
FileSelected = .Show
End With
If FileSelected <> False Then
Application.DisplayAlerts = False
ThisWorkbook.SaveAs Filename:=FileSelector.SelectedItems(1), _
FileFormat:=51
Application.DisplayAlerts = True
End If
Set FileSelector = Nothing
End Sub
When I try to save the workbook, the program crashes on this line:
Code:
MyArray() = Sheet1.Cells(1, 1).CurrentRegion.Value
Can someone tell me what is wrong?
It seems the program cannot "see" the data and read it into MyArray.
Thanks