I have an Excel 2003 spreadsheet ("Tune.xls") with some VBA. It always fails with error:
Run Time Error 1004 'Application Defined or Object Defined Error'
When I click debug it brings me to the following line in the code :
DataImport.Range("J10").Value = FileName 'Copy path and filename to worksheet "Import Data"
and also please look into whole code as follows:
'Ensure that all global (public) flags are initialized properly; they might have been
'changed before the user requested a data import.
Sub_Error = False
Changed_Model_1 = False
Changed_Model_2 = False
Plot_Model_1 = False
Plot_Model_2 = False
Updated_Model_1 = False
Updated_Model_2 = False
'Disable screen updating to avoid flicker when graph data is modified. Puting the focus away
'from the graph to worksheet "Data Import" speeds up the execution by a factor of about 4. This trick
'is ad hoc and I cannot explain why it works, but it does...
Application.ScreenUpdating = False
DataImport.Select
'Open window to select data file. If no file is opened, then the variable FileName will be false.
FileName = Application.GetOpenFilename("Text Files (*.txt; *.dat),*.txt;*.dat, Excel Files (*.xls),*.xls", , "Open Process Data File")
If FileName = False Then Exit Sub 'exit if no file was opened or cancel button selected
******DataImport.Range("J10").Value = FileName 'Copy path and filename to worksheet "Import Data"******
'Open data file as a workbook and use shortcut name "DataSheet" for worksheet containing data.
Workbooks.Open FileName:=FileName, updateLinks:=0 'does not update linked cells
Set DataSheet = ActiveWorkbook.ActiveSheet
Set DataBook = ActiveWorkbook 'use shortcut for Data workbook
'The data workbook might contain cells referencing a DDE link. This makes it hard to manipulate
'the cells. Therefore, the entire worksheet is copied and only the values are pasted back. This
'will essentially remove all the DDE references.
DataSheet.Cells.Select 'This selects all cells
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Please can somebody help me to get this working again?
Option Explicitand declaring your variables properly. This combination cures half the issues - Zac