Method 'Range' of object Global failed.

M

marilyn

I am encountered this message in the following code:

Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRange As Excel.Range

Set oExcel = CreateObject("Excel.Application")
IF FileExists(strFnameIn) Then
Set oBook = oExcel.Workbooks.Open(strFnameIn)
Else
Set oBook = oExcel.Workbooks.Add
oBook.SaveAs strFnameIn
End If

'Format numeric columns to currency format:
'Column 4-7:
Set oRange = Range("D:G")
With oRange
.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End With
'Change Column 1 format to text:
Set oRange = Range("A:A")
With oRange
.NumberFormat = "@"
end with

The first time I run the code, everything runs okay. When
I re-run the code I encounter the error on line:

Set oRange = (Range("D:G")

Thank you for all of your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top