Saving spreadsheet = invalid propert assignment?

option

Registered User.
Local time
Today, 03:51
Joined
Jul 3, 2008
Messages
143
Hey guys,

I'm trying to edit a spreadsheet that may or may not be missing data from an extraction we perform here. Basically, we take the data from our 2 job sites and compare them. However, there is the rare occasion that Site2 uses Site1's server, creating the misconception that no work was performed. When the extraction is put through our database, it errors out because Site2 is missing. I've come up with a loop that opens the extract (a spreadsheet) and places "0" for Site2's data. Once the loop is complete, I want it to save without prompting the user (since the rest of the task is automated) but my method does not work. Any Ideas??

Code:
Public Sub SiteChk()

On Error GoTo Err_Click

Dim appexcel As Object
Dim i As String
Dim dei As String

i = 2
    Set appexcel = CreateObject("Excel.Application")
    appexcel.workbooks.Open "C:\folder\Report.xls"
    appexcel.Visible = True

'Select Sheet in workbook
    appexcel.Sheets("Sheet1").Select


' Loop to add blank Site2 data to force update
    
    dei = appexcel.Range("A2")
    
    Do Until appexcel.Range("B" + i) = "Site2"
        If appexcel.Range("B" + i) = "Site1" Then
            i = i + 1
            Else
            If appexcel.Range("B" + i) = "" Then
            appexcel.Range("A" + i).Value = dei
            appexcel.Range("B" + i).Value = "Site2"
            appexcel.Range("C" + i).Value = "0"
            appexcel.Range("D" + i).Value = "0"
            appexcel.Range("E" + i).Value = "00-Jan-00"
            appexcel.Range("F" + i).Value = "00-Jan-00"
            appexcel.Range("G" + i).Value = "0"
            appexcel.Range("H" + i).Value = "0"
            appexcel.Range("I" + i).Value = "0"
            appexcel.Range("J" + i).Value = "0"
            appexcel.Range("K" + i).Value = "0.00%"
            appexcel.Range("L" + i).Value = "0.00%"
            appexcel.Range("M" + i).Value = "0"
            appexcel.Range("N" + i).Value = "0"
            appexcel.Range("O" + i).Value = "0"
            appexcel.Range("P" + i).Value = "0"
            appexcel.Range("Q" + i).Value = "0"
            appexcel.Range("R" + i).Value = "0"
            appexcel.Range("S" + i).Value = "0"
            appexcel.Range("T" + i).Value = "0"
            End If
        End If
                
     Loop
     
     appexcel.workbooks.Close True
  
Set appexcel = Nothing

Exit_Click:
    Exit Sub

Err_Click:
    MsgBox Err.Description
    Resume Exit_Click
End Sub
 
Try

appexcel.ActiveWorkbook.Save
 

Users who are viewing this thread

Back
Top Bottom