Running Excel VBA in IE

powerpackinduo

Board Regular
Joined
Jul 28, 2005
Messages
128
I am having trouble running Excel VBA code in an excel workbook through Internet Explorer (IE).
The code I have runs fine in Excel. But when I running by opening in IE I get an error.
For example trying to run the simple command
Range("A1").Select

Results in the error message Method 'Range' of object '_Global' Failed

What do I need to change in my code to get IE to run the code properly?

Here's my code:
Code:
Option Explicit
Public cnn As New Connection
Public bFlag As Boolean
Dim rs As Recordset
Dim e As ADODB.Error
Dim CYExtract As Date
Dim PYExtract As Date

Public Sub LoadData()

Dim msg As String
Dim extractDate As String

On Error GoTo AnError

Application.ScreenUpdating = False

'Set Current Year Extract Date to be the most current data in the datamart.
CYExtract = Date - 1

'Set Previous Year Extract Date to be the most current data for previous time period.
If Range("BeginDate").Value > CYExtract Then
    PYExtract = CYExtract
    Else: PYExtract = Range("BeginDate").Value
End If

'Check that Property box has a property selected.
If Params.cboProperty.ListIndex = -1 Then
  MsgBox "Please select a property from the drop down menu.", vbOKOnly + vbExclamation, "Select Property"
  Application.StatusBar = False
  Application.ScreenUpdating = True
  Exit Sub
End If

'Check that Begin Date is enterred.
If Range("BeginDate").Value = "" Then
  MsgBox "Please enter a Begin Date.", vbOKOnly + vbExclamation, "Missing Begin Date"
  Range("BeginDate").Select
  Application.StatusBar = False
  Application.ScreenUpdating = True
  Exit Sub
End If

'Check that End Date is enterred.
If Range("EndDate").Value = "" Then
  MsgBox "Please enter an End Date.", vbOKOnly + vbExclamation, "Missing End Date"
  Range("EndDate").Select
  Application.StatusBar = False
  Application.ScreenUpdating = True
  Exit Sub
End If

' When all fields have passed validation process request.
Application.StatusBar = "Processing request. Please wait..."

'Clear all old data
Previous.Range("A2:" + FindLastCell(Previous)).ClearContents
Current.Range("A2:" + FindLastCell(Current)).ClearContents

'First the previous reservations sheet
If Not FormatSQL(CStr(PYExtract), CStr(DateAdd("yyyy", -1, Range("BeginDate").Value)), CStr(DateAdd("yyyy", -1, Range("EndDate").Value))) Then
  Application.StatusBar = False
  Application.ScreenUpdating = True
  Exit Sub
End If
Set rs = GetRecordset(sSQL)
Previous.Range("A2").CopyFromRecordset rs

'Verify records were returned for previous period extract.
If Previous.Cells(Rows.Count, "D").End(xlUp).row = 1 Then
    MsgBox "The parameters selected did not return any records for the previous period.  No list can be generated.", vbOKOnly + vbExclamation, "No Previous Records"
    Application.StatusBar = False
    Params.cboProperty.Activate
    Application.ScreenUpdating = True
    Exit Sub
End If

'Now the current reservations sheet
If Not FormatSQL(CStr(CYExtract), CStr(Range("BeginDate").Value), CStr(Range("EndDate").Value)) Then
  Application.StatusBar = False
  Application.ScreenUpdating = True
  Exit Sub
End If
Set rs = GetRecordset(sSQL)
Current.Range("A2").CopyFromRecordset rs

If cnn.State Then cnn.Close

'Create/Update Not Reserved sheet
Call NotReserved

'Delete Dupes on Not Reserved sheet
If Params.chkDeleteDupes.Value Then
  Sheets("Not Reserved").Select
  Call DeleteDuplicates
End If

'Sort and format all sheets in active workbook except the first (parameters)
    Application.StatusBar = "Formatting sheets..."
    
    For Each ws In ActiveWorkbook.Sheets
        If ws.Name <> "Parameters" Then
          ws.Activate
          FormatSheet
        End If
    Next ws

Application.StatusBar = False
Application.ScreenUpdating = True

Exit Sub
  
AnError:
  For Each e In cnn.Errors
  msg = msg + e.Description + vbLf
  Next
  MsgBox Err.Description + vbLf + msg + vbLf + "in LoadData"
 Err.Raise Err.Number, "LoadData", Err.Description
  
If cnn.State Then cnn.Close

Application.StatusBar = False
Application.ScreenUpdating = True

End Sub
 
I'm using xl2000 also.
It's not Excel, it's the IE environment. I'm looking to find what I need to change in the code for the IE environment to manipulate the file correctly.

In Excel 2000 my code works just fine. But it needs to be ran in IE.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Wish I could help you, but other than saying to install IE8, I don't have any idea. Normally when you get the error you are, it is looking for a reference.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,019
Members
448,938
Latest member
Aaliya13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top