eahowell
06-01-2011, 08:44 AM
Background Information:
I have written a set of code that upon opening the document it prompts the user to open and insert data from a .txt file of data and separate the data into the appropriate cells then prompt the user to SaveAs.
Then intention of this is to take a large quantity of data and bring it into Excel to then analyze it or view it later.
Problem/Next Step:
Now the issue I have is when you go to open one of the saved documents of data after it's been separated it runs the macro again.
Is there a command to to kill Workbook_Open event?
I was trying an if statement to check if the name of the file name is the original or one of the saved but I am not sure the correct syntax since I do not have much VBA experience.
I put my code below but I know this isn't right since it won't compile.
Code:
Private Sub Workbook_Open()
Dim WBName As String
ActiveWorkbook.Name = WBName
If WBName = "DataExporter.xls" Then
'Everything below here within the IF statement runs correctly
Dim cell_1, cell_2, rng_1 As Range
Sheet1.Cells.Clear
Set cell_1 = Cells(1, 1)
Set cell_2 = Cells(1, 1)
Set rng_1 = Range(cell_1, cell_2)
rng_1.Select
Call DoTheImport
Call SeparateData
Else
End If
End Function
Thanks in advance!
Liz
I have written a set of code that upon opening the document it prompts the user to open and insert data from a .txt file of data and separate the data into the appropriate cells then prompt the user to SaveAs.
Then intention of this is to take a large quantity of data and bring it into Excel to then analyze it or view it later.
Problem/Next Step:
Now the issue I have is when you go to open one of the saved documents of data after it's been separated it runs the macro again.
Is there a command to to kill Workbook_Open event?
I was trying an if statement to check if the name of the file name is the original or one of the saved but I am not sure the correct syntax since I do not have much VBA experience.
I put my code below but I know this isn't right since it won't compile.
Code:
Private Sub Workbook_Open()
Dim WBName As String
ActiveWorkbook.Name = WBName
If WBName = "DataExporter.xls" Then
'Everything below here within the IF statement runs correctly
Dim cell_1, cell_2, rng_1 As Range
Sheet1.Cells.Clear
Set cell_1 = Cells(1, 1)
Set cell_2 = Cells(1, 1)
Set rng_1 = Range(cell_1, cell_2)
rng_1.Select
Call DoTheImport
Call SeparateData
Else
End If
End Function
Thanks in advance!
Liz