Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Corrupt Code

Status
Not open for further replies.

Codemage

Computer
Jun 2, 2003
6
the Code that worked GREAT for 4 days then WHAM Nothing but error's >>??? what up ("PULLING HAIR")

'Using DDE Animate for TAG values

Dim objExcel As Object
Dim sExcelFilePath As String
Dim ExcelWasNotRunning As Boolean
Set objExcel = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.
sExcelFilePath = gProject.Path & &quot;\sRecipe.xls&quot;
Set objExcel = GetObject(sExcelFilePath)
'Calday = UserForm1.Calendar1.Today
'TAGS to Set and Read Go Here
With objExcel.Application.WorkBooks(&quot;sRecipe.xls&quot;).Worksheets(&quot;Daily&quot;)
Set tag1 = gTagDb.GetTag(&quot;RDFAST&quot;)
Set tag2 = gTagDb.GetTag(&quot;SAWTOOTH&quot;)
Set tag3 = gTagDb.GetTag(&quot;RUFAST&quot;)
Set Tag4 = gTagDb.GetTag(&quot;SAWTOOTH&quot;)
Set tag5 = gTagDb.GetTag(&quot;SINEFAST&quot;)
Set tag6 = gTagDb.GetTag(&quot;RUFAST&quot;)
Set Tag7 = gTagDb.GetTag(&quot;day&quot;)
'Set the Font
.Rows(1).Font.Bold = True
'Format the headings in Excel
Step = Tag7.Value
If Step < 1 Or Step = 31 Then Step = Step + 6 ' starting cell After end of Month and clear
Step = Step + 1

'Write the data to Excel By Step Value
.Cells(Step, 2).Value = Date
.Cells(Step, 3).Value = gTagDb.GetTag(&quot;RDFAST&quot;).Value
.Cells(Step, 4).Value = gTagDb.GetTag(&quot;SAWTOOTH&quot;).Value
.Cells(Step, 5).Value = gTagDb.GetTag(&quot;SINEFAST&quot;).Value
.Cells(Step, 6).Value = gTagDb.GetTag(&quot;RUFAST&quot;).Value
.Cells(Step, 7).Value = gTagDb.GetTag(&quot;SAWTOOTH&quot;).Value
' Print to the Windows default printer
'.PrintOut Copies:=1, Collate:=True
End With

' If this copy of Microsoft Excel was not already running when you
' started, close it using the Application property's Quit method.

If ExcelWasNotRunning = True Then

'This prevents the Save Changes dialog from displaying

objExcel.Application.DisplayAlerts = False

'No changes are saved upon quitting

objExcel.Application.Quit
End If

'JUMP TO CLOSE
GoTo Clos
bottom:
tag1.Value = 1
MESS = Err.Description
MsgBox MESS
Err.Clear
GoTo clos2

Clos:
tag1.Value = 1
clos2:
' WorkBooks.Close
Set tag1 = Nothing
Set tag2 = Nothing
Set tag3 = Nothing
Set Tag4 = Nothing
Set tag5 = Nothing
End Sub
 
Replies continue below

Recommended for you

Well, have you single stepped it to see where it fails?
What is the error message?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor