PC Review


Reply
Thread Tools Rate Thread

close workbook/pdf conversion

 
 
=?Utf-8?B?VG9kZEVa?=
Guest
Posts: n/a
 
      19th Jun 2007
I have a macro that creates copys data from a sheet called "template", pastes
it into a sheet called "tempsheet", then converts "tempsheet" to a pdf, and
attaches it to an email. However, during the PDF conversion process, my
original workbook is closed, and I am left with the temporary workbook
created to form the PDF. I would like to kill the temporary file, and leave
open the template. Here is the context surrounding the PDF conversion. Any
help would be great. Thanks!

Sheets("TempSheet").Activate
Dim lastPrinter As String, myPath As String
Dim myFileName As String, Wb As Workbook
myPath = "U:\Temp\"
myFileName = Sheets("Template").Range("B1")
myfullpath = myPath & myFileName & ".xls"
Worksheets("TempSheet").Range("a1:f100").Copy
Set Wb = ActiveWorkbook
Wb.SaveAs myfullpath
lastPrinter = Application.ActivePrinter
Application.ActivePrinter = "Adobe PDF on Ne05:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Wb.Close (False)
Kill myfullpath
Application.ActivePrinter = lastPrinter
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2xheW1hbg==?=
Guest
Posts: n/a
 
      19th Jun 2007
What about doing this:

kill Wb

Instead of

kill myfullpath


--
Adios,
Clay Harryman


"ToddEZ" wrote:

> I have a macro that creates copys data from a sheet called "template", pastes
> it into a sheet called "tempsheet", then converts "tempsheet" to a pdf, and
> attaches it to an email. However, during the PDF conversion process, my
> original workbook is closed, and I am left with the temporary workbook
> created to form the PDF. I would like to kill the temporary file, and leave
> open the template. Here is the context surrounding the PDF conversion. Any
> help would be great. Thanks!
>
> Sheets("TempSheet").Activate
> Dim lastPrinter As String, myPath As String
> Dim myFileName As String, Wb As Workbook
> myPath = "U:\Temp\"
> myFileName = Sheets("Template").Range("B1")
> myfullpath = myPath & myFileName & ".xls"
> Worksheets("TempSheet").Range("a1:f100").Copy
> Set Wb = ActiveWorkbook
> Wb.SaveAs myfullpath
> lastPrinter = Application.ActivePrinter
> Application.ActivePrinter = "Adobe PDF on Ne05:"
> ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
> Wb.Close (False)
> Kill myfullpath
> Application.ActivePrinter = lastPrinter

 
Reply With Quote
 
=?Utf-8?B?VG9kZEVa?=
Guest
Posts: n/a
 
      19th Jun 2007
Unfortunately that yielded the same results. Thanks for the suggestion though.

"Clayman" wrote:

> What about doing this:
>
> kill Wb
>
> Instead of
>
> kill myfullpath
>
>
> --
> Adios,
> Clay Harryman
>
>
> "ToddEZ" wrote:
>
> > I have a macro that creates copys data from a sheet called "template", pastes
> > it into a sheet called "tempsheet", then converts "tempsheet" to a pdf, and
> > attaches it to an email. However, during the PDF conversion process, my
> > original workbook is closed, and I am left with the temporary workbook
> > created to form the PDF. I would like to kill the temporary file, and leave
> > open the template. Here is the context surrounding the PDF conversion. Any
> > help would be great. Thanks!
> >
> > Sheets("TempSheet").Activate
> > Dim lastPrinter As String, myPath As String
> > Dim myFileName As String, Wb As Workbook
> > myPath = "U:\Temp\"
> > myFileName = Sheets("Template").Range("B1")
> > myfullpath = myPath & myFileName & ".xls"
> > Worksheets("TempSheet").Range("a1:f100").Copy
> > Set Wb = ActiveWorkbook
> > Wb.SaveAs myfullpath
> > lastPrinter = Application.ActivePrinter
> > Application.ActivePrinter = "Adobe PDF on Ne05:"
> > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
> > Wb.Close (False)
> > Kill myfullpath
> > Application.ActivePrinter = lastPrinter

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      19th Jun 2007

Dim lastPrinter As String, myPath As String
Dim WB as Workbook, WB1 as Workbook
Dim rng as Range
Dim myFileName As String, Wb As Workbook
Sheets("TempSheet").Activate
myPath = "U:\Temp\"
myFileName = Sheets("Template").Range("B1")
myfullpath = myPath & myFileName & ".xls"
Set Wb1 = ActiveWorkbook
set rng = WB1.Worksheets("TempSheet").Range("a1:f100")
set WB = Workbooks.Add(Template:=xlWBATWorksheet)
rng.copy WB.Worksheets(1).Range("A1")
Wb.SaveAs myfullpath
lastPrinter = Application.ActivePrinter
Application.ActivePrinter = "Adobe PDF on Ne05:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Wb.Close (False)
Kill myfullpath
Application.ActivePrinter = lastPrinter

--
Regards,
Tom Ogilvy

"ToddEZ" wrote:

> I have a macro that creates copys data from a sheet called "template", pastes
> it into a sheet called "tempsheet", then converts "tempsheet" to a pdf, and
> attaches it to an email. However, during the PDF conversion process, my
> original workbook is closed, and I am left with the temporary workbook
> created to form the PDF. I would like to kill the temporary file, and leave
> open the template. Here is the context surrounding the PDF conversion. Any
> help would be great. Thanks!
>
> Sheets("TempSheet").Activate
> Dim lastPrinter As String, myPath As String
> Dim myFileName As String, Wb As Workbook
> myPath = "U:\Temp\"
> myFileName = Sheets("Template").Range("B1")
> myfullpath = myPath & myFileName & ".xls"
> Worksheets("TempSheet").Range("a1:f100").Copy
> Set Wb = ActiveWorkbook
> Wb.SaveAs myfullpath
> lastPrinter = Application.ActivePrinter
> Application.ActivePrinter = "Adobe PDF on Ne05:"
> ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
> Wb.Close (False)
> Kill myfullpath
> Application.ActivePrinter = lastPrinter

 
Reply With Quote
 
=?Utf-8?B?VG9kZEVa?=
Guest
Posts: n/a
 
      19th Jun 2007
this worked great! thanks for taking the time to help.

"Tom Ogilvy" wrote:

>
> Dim lastPrinter As String, myPath As String
> Dim WB as Workbook, WB1 as Workbook
> Dim rng as Range
> Dim myFileName As String, Wb As Workbook
> Sheets("TempSheet").Activate
> myPath = "U:\Temp\"
> myFileName = Sheets("Template").Range("B1")
> myfullpath = myPath & myFileName & ".xls"
> Set Wb1 = ActiveWorkbook
> set rng = WB1.Worksheets("TempSheet").Range("a1:f100")
> set WB = Workbooks.Add(Template:=xlWBATWorksheet)
> rng.copy WB.Worksheets(1).Range("A1")
> Wb.SaveAs myfullpath
> lastPrinter = Application.ActivePrinter
> Application.ActivePrinter = "Adobe PDF on Ne05:"
> ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
> Wb.Close (False)
> Kill myfullpath
> Application.ActivePrinter = lastPrinter
>
> --
> Regards,
> Tom Ogilvy
>
> "ToddEZ" wrote:
>
> > I have a macro that creates copys data from a sheet called "template", pastes
> > it into a sheet called "tempsheet", then converts "tempsheet" to a pdf, and
> > attaches it to an email. However, during the PDF conversion process, my
> > original workbook is closed, and I am left with the temporary workbook
> > created to form the PDF. I would like to kill the temporary file, and leave
> > open the template. Here is the context surrounding the PDF conversion. Any
> > help would be great. Thanks!
> >
> > Sheets("TempSheet").Activate
> > Dim lastPrinter As String, myPath As String
> > Dim myFileName As String, Wb As Workbook
> > myPath = "U:\Temp\"
> > myFileName = Sheets("Template").Range("B1")
> > myfullpath = myPath & myFileName & ".xls"
> > Worksheets("TempSheet").Range("a1:f100").Copy
> > Set Wb = ActiveWorkbook
> > Wb.SaveAs myfullpath
> > lastPrinter = Application.ActivePrinter
> > Application.ActivePrinter = "Adobe PDF on Ne05:"
> > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
> > Wb.Close (False)
> > Kill myfullpath
> > Application.ActivePrinter = lastPrinter

 
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
error in running workbook.close() func. after close excel from win Kayıhan Microsoft C# .NET 0 29th Mar 2009 12:49 AM
Close a Excel Workbook when close a userform in Outlook lars.oyangen@hamstad.no Microsoft Outlook VBA Programming 2 8th May 2008 02:54 PM
Closing a workbook from a macro doesn't close the workbook =?Utf-8?B?RGF2ZSBQ?= Microsoft Excel Programming 2 10th Jul 2007 06:16 PM
Excel VBA Close Workbook and Open Existing Workbook rjm65 Microsoft Excel Programming 1 22nd Dec 2004 06:56 AM
Excel 2000 Workbook close button hides instead of close Steven Robinson Microsoft Excel Misc 3 13th Aug 2003 11:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:37 PM.