View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
BruceS BruceS is offline
external usenet poster
 
Posts: 5
Default Resume.xlw and closing workbook with VBA code.

Hi, all.

I'm an Access programmer working on a .mdb that creates an Excel
spreadsheet. After doing so, I need to open the worksheet, edit it to set
consistent heading formats, then close it. The spreadsheet creates
beautifully, and all of the formatting that I want is applied to it, but I
have two glitches when trying to close it:

1) The .Close command generates a "method not supported for this object"
error.
2) When I then try to close it manually, I get an error message that reads
"A file named 'RESUME.XLW' already exists in this location. Do you want to
replace it?

I've only done fairly simple macros in Excel, usually creating them with
recorder and making minor modifications, so I'm not familiar "resume.xlw".
Only found a couple of posts dealing with it when I searched here, and they
weren't much help.

The sub is below. Can anyone out there help?

Thanks,
Bruce

Sub SetSpreadsheetHeadings(forFilePath)
On Error GoTo SpreadsheetErr
'
' Sets headings for new spreadsheet.
'
Dim MyXL As Object

Set MyXL = CreateObject("Excel.Application")

With MyXL
.Workbooks.Open forFilePath

'I'd rather not make it visible at all, if I can do it that way.
.Application.Visible = True
.Parent.Windows(1).Visible = True

.Rows("1:1").Select
.Selection.Font.FontStyle = "Bold"
.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
.Selection.Borders(xlEdgeLeft).LineStyle = xlNone
.Selection.Borders(xlEdgeTop).LineStyle = xlNone
With .Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.Selection.Borders(xlEdgeRight).LineStyle = xlNone
.Selection.Borders(xlInsideVertical).LineStyle = xlNone
With .Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
.Cells.Select
.Selection.Columns.AutoFit
.Columns("A:A").Select
.Selection.EntireColumn.Hidden = True

'Unhighlight rows left selected.
.Range("B2").Select

.Save
DoEvents

.Close 'Causes error.
End With

Set MyXL = Nothing

Exit Sub

SpreadsheetErr:
MsgBox "Error editing spreadsheet:" & vbCr & vbCr & _
"Error Code: " & Err.Number & vbCr & _
Err.Description, vbOKCritical, "Error!"
Err.Clear

End Sub