PC Review


Reply
Thread Tools Rate Thread

Deleting sheet from a template

 
 
mcescher
Guest
Posts: n/a
 
      5th Apr 2010
Hi All,
I've got an Excel file formatted with several sheets that each have
some headers that I use as a template to paste my data in. One of the
sheets may or may not receive information. If I don't have any
records to paste into that sheet, I'd like to delete it. Because of
the formatted headers, Excel gives an error message. I tried a
DoCmd.SetWarnings False, but apparently that stops at Access.

strWSName = "Future"
Set rs = db.OpenRecordset("UnprocessedFuture", dbOpenDynaset)
Set xlsReport = xlbReport.Worksheets(strWSName)
With rs
.MoveLast
.MoveFirst
intRows = rs.RecordCount
If intRows > 0 Then
xlsReport.Range("A7").CopyFromRecordset rs
GoSub FormatSheet
xlsReport.Range("H4").Formula = "=Sum_Visible_Cells(J7:J" &
intRows + 6 & ")"
Else
DoCmd.SetWarnings False
'Error message appears for this line
xlsReport.Delete
DoCmd.SetWarnings True
End If
End With


Would it work to delete all the information from the sheet and then
remove it? Would I be better off just hiding the sheet, or is there a
way I can delete it.

Thanks so much,
Chris M.
 
Reply With Quote
 
 
 
 
RonaldoOneNil
Guest
Posts: n/a
 
      6th Apr 2010
I assume you have a variable that is your Excel application Object. You need
to turn off warnings using this variable

xlApp.DisplayAlerts = False
xlbReport.Worksheets(strWSName).Delete
xlApp.DisplayAlerts = True

"mcescher" wrote:

> Hi All,
> I've got an Excel file formatted with several sheets that each have
> some headers that I use as a template to paste my data in. One of the
> sheets may or may not receive information. If I don't have any
> records to paste into that sheet, I'd like to delete it. Because of
> the formatted headers, Excel gives an error message. I tried a
> DoCmd.SetWarnings False, but apparently that stops at Access.
>
> strWSName = "Future"
> Set rs = db.OpenRecordset("UnprocessedFuture", dbOpenDynaset)
> Set xlsReport = xlbReport.Worksheets(strWSName)
> With rs
> .MoveLast
> .MoveFirst
> intRows = rs.RecordCount
> If intRows > 0 Then
> xlsReport.Range("A7").CopyFromRecordset rs
> GoSub FormatSheet
> xlsReport.Range("H4").Formula = "=Sum_Visible_Cells(J7:J" &
> intRows + 6 & ")"
> Else
> DoCmd.SetWarnings False
> 'Error message appears for this line
> xlsReport.Delete
> DoCmd.SetWarnings True
> End If
> End With
>
>
> Would it work to delete all the information from the sheet and then
> remove it? Would I be better off just hiding the sheet, or is there a
> way I can delete it.
>
> Thanks so much,
> Chris M.
> .
>

 
Reply With Quote
 
mcescher
Guest
Posts: n/a
 
      6th Apr 2010
On Apr 6, 5:46*am, RonaldoOneNil
<RonaldoOne...@discussions.microsoft.com> wrote:
> I assume you have a variable that is your Excel application Object. You need
> to turn off warnings using this variable
>
> xlApp.DisplayAlerts = False
> xlbReport.Worksheets(strWSName).Delete
> xlApp.DisplayAlerts = True
>



Yup, I do have an app variable. That did the trick, thanks so much.

Chris M.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copying a template sheet and inputting a formula into another sheetthat references the new sheet A & S Microsoft Excel Programming 1 29th Jul 2009 08:59 PM
deleting rows from one sheet based on 2nd sheet =?Utf-8?B?bWFnb2xkMjAwNUBob3RtYWlsLmNvbQ==?= Microsoft Excel Discussion 1 6th Sep 2007 07:38 AM
How to merge data in Excel - one sheet to template sheet? =?Utf-8?B?R2FicmllbGE=?= Microsoft Excel Worksheet Functions 2 26th Jul 2007 03:34 PM
Create new sheets based off Data sheet, and template sheet Midget Microsoft Excel Programming 2 1st May 2007 09:55 PM
Writing data from one sheet to another template sheet and change the filename freeblue11@gmail.com Microsoft Excel Discussion 1 2nd Nov 2006 03:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:00 PM.