PC Review


Reply
Thread Tools Rate Thread

CreateObject from Template

 
 
Paul3rd
Guest
Posts: n/a
 
      5th Jan 2008
Hello, I can't get the following code to execute correctly. It creates a new
worksheet, but not from a template as I intended.
Can anyone help?
>Sub CTMacro()
>On Error Resume Next
> Dim ExcelSheet As Object
>
>Application.DisplayAlerts = False
>Set ExcelSheet = CreateObject("Excel.Sheet")
>Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
>
> With Workbooks("Copy of ApptDis.xls")
> .Worksheets("Sheet1").Range("B2:I2").Copy
> ExcelSheet.Application.Visible = True
> With ExcelSheet.ActiveSheet.Range("B2:I2")
> .PasteSpecial xlPasteValues
>
> ExcelSheet.SaveAs "C:\CTest.xls"
> Application.DisplayAlerts = True
> End With
> End With
>End Sub

Thanks in advance for any help.
Paul
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      5th Jan 2008
Dim ExcelSheet As Object
set ExcelSheet = sheets.Add(type:="c:\ctest.xlt")



Paul3rd wrote:
>
> Hello, I can't get the following code to execute correctly. It creates a new
> worksheet, but not from a template as I intended.
> Can anyone help?
> >Sub CTMacro()
> >On Error Resume Next
> > Dim ExcelSheet As Object
> >
> >Application.DisplayAlerts = False
> >Set ExcelSheet = CreateObject("Excel.Sheet")
> >Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
> >
> > With Workbooks("Copy of ApptDis.xls")
> > .Worksheets("Sheet1").Range("B2:I2").Copy
> > ExcelSheet.Application.Visible = True
> > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > .PasteSpecial xlPasteValues
> >
> > ExcelSheet.SaveAs "C:\CTest.xls"
> > Application.DisplayAlerts = True
> > End With
> > End With
> >End Sub

> Thanks in advance for any help.
> Paul


--

Dave Peterson
 
Reply With Quote
 
Paul3rd
Guest
Posts: n/a
 
      5th Jan 2008
Dave, Thanks for your reply, I changed the code to the following but no new
workbook/worksheet is created.

>Sub CTMacro()
>On Error Resume Next
> Dim ExcelSheet As Object
>
>Application.DisplayAlerts = False
>Set ExcelSheet = Sheets.Add(Type:="C:\CTest.xlt")
>
> With Workbooks("Copy of ApptDis.xls")
> .Worksheets("Sheet1").Range("B2:I2").Copy
> ExcelSheet.Application.Visible = True
> With ExcelSheet.ActiveSheet.Range("B2:I2")
> .PasteSpecial xlPasteValues>
>
> ExcelSheet.SaveAs "C:\DaveTest.xls"
> Application.DisplayAlerts = True
> End With
> End With
>End Sub


"Dave Peterson" wrote:

> Dim ExcelSheet As Object
> set ExcelSheet = sheets.Add(type:="c:\ctest.xlt")
>
>
>
> Paul3rd wrote:
> >
> > Hello, I can't get the following code to execute correctly. It creates a new
> > worksheet, but not from a template as I intended.
> > Can anyone help?
> > >Sub CTMacro()
> > >On Error Resume Next
> > > Dim ExcelSheet As Object
> > >
> > >Application.DisplayAlerts = False
> > >Set ExcelSheet = CreateObject("Excel.Sheet")
> > >Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
> > >
> > > With Workbooks("Copy of ApptDis.xls")
> > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > ExcelSheet.Application.Visible = True
> > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > .PasteSpecial xlPasteValues
> > >
> > > ExcelSheet.SaveAs "C:\CTest.xls"
> > > Application.DisplayAlerts = True
> > > End With
> > > End With
> > >End Sub

> > Thanks in advance for any help.
> > Paul

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Jan 2008
Remove or comment the "on error resume next" line.

I bet that it's masking an error.

(You sure that C:\cTest.xlt actually exists?)

Paul3rd wrote:
>
> Dave, Thanks for your reply, I changed the code to the following but no new
> workbook/worksheet is created.
>
> >Sub CTMacro()
> >On Error Resume Next
> > Dim ExcelSheet As Object
> >
> >Application.DisplayAlerts = False
> >Set ExcelSheet = Sheets.Add(Type:="C:\CTest.xlt")
> >
> > With Workbooks("Copy of ApptDis.xls")
> > .Worksheets("Sheet1").Range("B2:I2").Copy
> > ExcelSheet.Application.Visible = True
> > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > .PasteSpecial xlPasteValues>
> >
> > ExcelSheet.SaveAs "C:\DaveTest.xls"
> > Application.DisplayAlerts = True
> > End With
> > End With
> >End Sub

>
> "Dave Peterson" wrote:
>
> > Dim ExcelSheet As Object
> > set ExcelSheet = sheets.Add(type:="c:\ctest.xlt")
> >
> >
> >
> > Paul3rd wrote:
> > >
> > > Hello, I can't get the following code to execute correctly. It creates a new
> > > worksheet, but not from a template as I intended.
> > > Can anyone help?
> > > >Sub CTMacro()
> > > >On Error Resume Next
> > > > Dim ExcelSheet As Object
> > > >
> > > >Application.DisplayAlerts = False
> > > >Set ExcelSheet = CreateObject("Excel.Sheet")
> > > >Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
> > > >
> > > > With Workbooks("Copy of ApptDis.xls")
> > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > ExcelSheet.Application.Visible = True
> > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > .PasteSpecial xlPasteValues
> > > >
> > > > ExcelSheet.SaveAs "C:\CTest.xls"
> > > > Application.DisplayAlerts = True
> > > > End With
> > > > End With
> > > >End Sub
> > > Thanks in advance for any help.
> > > Paul

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Paul3rd
Guest
Posts: n/a
 
      5th Jan 2008
Hello Dave,
You are correct, I didn't write the complete path to CTest.xlt.
I have the code working correctly now (in a new module) except for one small
thing...
The Jan5copytest.xls closes after code executes and I want to keep it open.
(I tried inserting a line Workbook.Open("C:\Jan5copytest') but it didn't work.

>Sub NewModule()
>Dim MyWB As Workbook
>
>Application.DisplayAlerts = False
>Set MyWB = Workbooks.Add("C:\FolderAppt\CTest.xlt")
> With Workbooks("Jan5copytest.xls")
> .Worksheets("Sheet1").Range("B2:I2").Copy
>
>
> MyWB.Application.Visible = False
> With MyWB.Sheets("Sheet1").Range("B2:I2")
> .PasteSpecial xlPasteValues
>
>MyWB.SaveAs ("C:\CCTest.xls")
>MyWB.Close (True)
>Workbooks.Open ("C:\Documents and Settings\Administrator\My >Documents\Excel Code Tests\Jan5copytest.xls")
>Application.DisplayAlerts = True
> End With
> End With
>
>End Sub


"Dave Peterson" wrote:

> Remove or comment the "on error resume next" line.
>
> I bet that it's masking an error.
>
> (You sure that C:\cTest.xlt actually exists?)
>
> Paul3rd wrote:
> >
> > Dave, Thanks for your reply, I changed the code to the following but no new
> > workbook/worksheet is created.
> >
> > >Sub CTMacro()
> > >On Error Resume Next
> > > Dim ExcelSheet As Object
> > >
> > >Application.DisplayAlerts = False
> > >Set ExcelSheet = Sheets.Add(Type:="C:\CTest.xlt")
> > >
> > > With Workbooks("Copy of ApptDis.xls")
> > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > ExcelSheet.Application.Visible = True
> > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > .PasteSpecial xlPasteValues>
> > >
> > > ExcelSheet.SaveAs "C:\DaveTest.xls"
> > > Application.DisplayAlerts = True
> > > End With
> > > End With
> > >End Sub

> >
> > "Dave Peterson" wrote:
> >
> > > Dim ExcelSheet As Object
> > > set ExcelSheet = sheets.Add(type:="c:\ctest.xlt")
> > >
> > >
> > >
> > > Paul3rd wrote:
> > > >
> > > > Hello, I can't get the following code to execute correctly. It creates a new
> > > > worksheet, but not from a template as I intended.
> > > > Can anyone help?
> > > > >Sub CTMacro()
> > > > >On Error Resume Next
> > > > > Dim ExcelSheet As Object
> > > > >
> > > > >Application.DisplayAlerts = False
> > > > >Set ExcelSheet = CreateObject("Excel.Sheet")
> > > > >Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
> > > > >
> > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > ExcelSheet.Application.Visible = True
> > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > .PasteSpecial xlPasteValues
> > > > >
> > > > > ExcelSheet.SaveAs "C:\CTest.xls"
> > > > > Application.DisplayAlerts = True
> > > > > End With
> > > > > End With
> > > > >End Sub
> > > > Thanks in advance for any help.
> > > > Paul
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Jan 2008
I don't understand.

I thought you wanted a worksheet added to an existing workbook--not a new
workbook.

And if Jan5copytest.xls is already open (you used it in your With statement),
why are you trying to open it again.

And is there a reason you're not copying the code from the VBE and pasting it
into your message.

To me, those ">" brackets mean that the stuff you posted isn't the same as the
code you're testing.

Paul3rd wrote:
>
> Hello Dave,
> You are correct, I didn't write the complete path to CTest.xlt.
> I have the code working correctly now (in a new module) except for one small
> thing...
> The Jan5copytest.xls closes after code executes and I want to keep it open.
> (I tried inserting a line Workbook.Open("C:\Jan5copytest') but it didn't work.
>
> >Sub NewModule()
> >Dim MyWB As Workbook
> >
> >Application.DisplayAlerts = False
> >Set MyWB = Workbooks.Add("C:\FolderAppt\CTest.xlt")
> > With Workbooks("Jan5copytest.xls")
> > .Worksheets("Sheet1").Range("B2:I2").Copy
> >
> >
> > MyWB.Application.Visible = False
> > With MyWB.Sheets("Sheet1").Range("B2:I2")
> > .PasteSpecial xlPasteValues
> >
> >MyWB.SaveAs ("C:\CCTest.xls")
> >MyWB.Close (True)
> >Workbooks.Open ("C:\Documents and Settings\Administrator\My >Documents\Excel Code Tests\Jan5copytest.xls")
> >Application.DisplayAlerts = True
> > End With
> > End With
> >
> >End Sub

>
> "Dave Peterson" wrote:
>
> > Remove or comment the "on error resume next" line.
> >
> > I bet that it's masking an error.
> >
> > (You sure that C:\cTest.xlt actually exists?)
> >
> > Paul3rd wrote:
> > >
> > > Dave, Thanks for your reply, I changed the code to the following but no new
> > > workbook/worksheet is created.
> > >
> > > >Sub CTMacro()
> > > >On Error Resume Next
> > > > Dim ExcelSheet As Object
> > > >
> > > >Application.DisplayAlerts = False
> > > >Set ExcelSheet = Sheets.Add(Type:="C:\CTest.xlt")
> > > >
> > > > With Workbooks("Copy of ApptDis.xls")
> > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > ExcelSheet.Application.Visible = True
> > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > .PasteSpecial xlPasteValues>
> > > >
> > > > ExcelSheet.SaveAs "C:\DaveTest.xls"
> > > > Application.DisplayAlerts = True
> > > > End With
> > > > End With
> > > >End Sub
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > Dim ExcelSheet As Object
> > > > set ExcelSheet = sheets.Add(type:="c:\ctest.xlt")
> > > >
> > > >
> > > >
> > > > Paul3rd wrote:
> > > > >
> > > > > Hello, I can't get the following code to execute correctly. It creates a new
> > > > > worksheet, but not from a template as I intended.
> > > > > Can anyone help?
> > > > > >Sub CTMacro()
> > > > > >On Error Resume Next
> > > > > > Dim ExcelSheet As Object
> > > > > >
> > > > > >Application.DisplayAlerts = False
> > > > > >Set ExcelSheet = CreateObject("Excel.Sheet")
> > > > > >Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
> > > > > >
> > > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > > ExcelSheet.Application.Visible = True
> > > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > > .PasteSpecial xlPasteValues
> > > > > >
> > > > > > ExcelSheet.SaveAs "C:\CTest.xls"
> > > > > > Application.DisplayAlerts = True
> > > > > > End With
> > > > > > End With
> > > > > >End Sub
> > > > > Thanks in advance for any help.
> > > > > Paul
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Paul3rd
Guest
Posts: n/a
 
      5th Jan 2008
Dave, sorry for the confusion.
My original code did create a new workbook.
Now, Jan5copytest.xls is open, it has a command button that triggers the
module.
The module creates a new workbook from the template (CTest.xlt), copies a
range to it, saves the new workbook as (CCTest.xls) and then closes it.
Which is what I wanted.
The module is also closing Jan5copytest.xls which is not what I wanted.
I won't use the > character anymore.
Paul

"Dave Peterson" wrote:

> I don't understand.
>
> I thought you wanted a worksheet added to an existing workbook--not a new
> workbook.
>
> And if Jan5copytest.xls is already open (you used it in your With statement),
> why are you trying to open it again.
>
> And is there a reason you're not copying the code from the VBE and pasting it
> into your message.
>
> To me, those ">" brackets mean that the stuff you posted isn't the same as the
> code you're testing.
>
> Paul3rd wrote:
> >
> > Hello Dave,
> > You are correct, I didn't write the complete path to CTest.xlt.
> > I have the code working correctly now (in a new module) except for one small
> > thing...
> > The Jan5copytest.xls closes after code executes and I want to keep it open.
> > (I tried inserting a line Workbook.Open("C:\Jan5copytest') but it didn't work.
> >
> > >Sub NewModule()
> > >Dim MyWB As Workbook
> > >
> > >Application.DisplayAlerts = False
> > >Set MyWB = Workbooks.Add("C:\FolderAppt\CTest.xlt")
> > > With Workbooks("Jan5copytest.xls")
> > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > >
> > >
> > > MyWB.Application.Visible = False
> > > With MyWB.Sheets("Sheet1").Range("B2:I2")
> > > .PasteSpecial xlPasteValues
> > >
> > >MyWB.SaveAs ("C:\CCTest.xls")
> > >MyWB.Close (True)
> > >Workbooks.Open ("C:\Documents and Settings\Administrator\My >Documents\Excel Code Tests\Jan5copytest.xls")
> > >Application.DisplayAlerts = True
> > > End With
> > > End With
> > >
> > >End Sub

> >
> > "Dave Peterson" wrote:
> >
> > > Remove or comment the "on error resume next" line.
> > >
> > > I bet that it's masking an error.
> > >
> > > (You sure that C:\cTest.xlt actually exists?)
> > >
> > > Paul3rd wrote:
> > > >
> > > > Dave, Thanks for your reply, I changed the code to the following but no new
> > > > workbook/worksheet is created.
> > > >
> > > > >Sub CTMacro()
> > > > >On Error Resume Next
> > > > > Dim ExcelSheet As Object
> > > > >
> > > > >Application.DisplayAlerts = False
> > > > >Set ExcelSheet = Sheets.Add(Type:="C:\CTest.xlt")
> > > > >
> > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > ExcelSheet.Application.Visible = True
> > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > .PasteSpecial xlPasteValues>
> > > > >
> > > > > ExcelSheet.SaveAs "C:\DaveTest.xls"
> > > > > Application.DisplayAlerts = True
> > > > > End With
> > > > > End With
> > > > >End Sub
> > > >
> > > > "Dave Peterson" wrote:
> > > >
> > > > > Dim ExcelSheet As Object
> > > > > set ExcelSheet = sheets.Add(type:="c:\ctest.xlt")
> > > > >
> > > > >
> > > > >
> > > > > Paul3rd wrote:
> > > > > >
> > > > > > Hello, I can't get the following code to execute correctly. It creates a new
> > > > > > worksheet, but not from a template as I intended.
> > > > > > Can anyone help?
> > > > > > >Sub CTMacro()
> > > > > > >On Error Resume Next
> > > > > > > Dim ExcelSheet As Object
> > > > > > >
> > > > > > >Application.DisplayAlerts = False
> > > > > > >Set ExcelSheet = CreateObject("Excel.Sheet")
> > > > > > >Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
> > > > > > >
> > > > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > > > ExcelSheet.Application.Visible = True
> > > > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > > > .PasteSpecial xlPasteValues
> > > > > > >
> > > > > > > ExcelSheet.SaveAs "C:\CTest.xls"
> > > > > > > Application.DisplayAlerts = True
> > > > > > > End With
> > > > > > > End With
> > > > > > >End Sub
> > > > > > Thanks in advance for any help.
> > > > > > Paul
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Jan 2008
How about posting your current version of the code?

Paul3rd wrote:
>
> Dave, sorry for the confusion.
> My original code did create a new workbook.
> Now, Jan5copytest.xls is open, it has a command button that triggers the
> module.
> The module creates a new workbook from the template (CTest.xlt), copies a
> range to it, saves the new workbook as (CCTest.xls) and then closes it.
> Which is what I wanted.
> The module is also closing Jan5copytest.xls which is not what I wanted.
> I won't use the > character anymore.
> Paul
>
> "Dave Peterson" wrote:
>
> > I don't understand.
> >
> > I thought you wanted a worksheet added to an existing workbook--not a new
> > workbook.
> >
> > And if Jan5copytest.xls is already open (you used it in your With statement),
> > why are you trying to open it again.
> >
> > And is there a reason you're not copying the code from the VBE and pasting it
> > into your message.
> >
> > To me, those ">" brackets mean that the stuff you posted isn't the same as the
> > code you're testing.
> >
> > Paul3rd wrote:
> > >
> > > Hello Dave,
> > > You are correct, I didn't write the complete path to CTest.xlt.
> > > I have the code working correctly now (in a new module) except for one small
> > > thing...
> > > The Jan5copytest.xls closes after code executes and I want to keep it open.
> > > (I tried inserting a line Workbook.Open("C:\Jan5copytest') but it didn't work.
> > >
> > > >Sub NewModule()
> > > >Dim MyWB As Workbook
> > > >
> > > >Application.DisplayAlerts = False
> > > >Set MyWB = Workbooks.Add("C:\FolderAppt\CTest.xlt")
> > > > With Workbooks("Jan5copytest.xls")
> > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > >
> > > >
> > > > MyWB.Application.Visible = False
> > > > With MyWB.Sheets("Sheet1").Range("B2:I2")
> > > > .PasteSpecial xlPasteValues
> > > >
> > > >MyWB.SaveAs ("C:\CCTest.xls")
> > > >MyWB.Close (True)
> > > >Workbooks.Open ("C:\Documents and Settings\Administrator\My >Documents\Excel Code Tests\Jan5copytest.xls")
> > > >Application.DisplayAlerts = True
> > > > End With
> > > > End With
> > > >
> > > >End Sub
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > Remove or comment the "on error resume next" line.
> > > >
> > > > I bet that it's masking an error.
> > > >
> > > > (You sure that C:\cTest.xlt actually exists?)
> > > >
> > > > Paul3rd wrote:
> > > > >
> > > > > Dave, Thanks for your reply, I changed the code to the following but no new
> > > > > workbook/worksheet is created.
> > > > >
> > > > > >Sub CTMacro()
> > > > > >On Error Resume Next
> > > > > > Dim ExcelSheet As Object
> > > > > >
> > > > > >Application.DisplayAlerts = False
> > > > > >Set ExcelSheet = Sheets.Add(Type:="C:\CTest.xlt")
> > > > > >
> > > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > > ExcelSheet.Application.Visible = True
> > > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > > .PasteSpecial xlPasteValues>
> > > > > >
> > > > > > ExcelSheet.SaveAs "C:\DaveTest.xls"
> > > > > > Application.DisplayAlerts = True
> > > > > > End With
> > > > > > End With
> > > > > >End Sub
> > > > >
> > > > > "Dave Peterson" wrote:
> > > > >
> > > > > > Dim ExcelSheet As Object
> > > > > > set ExcelSheet = sheets.Add(type:="c:\ctest.xlt")
> > > > > >
> > > > > >
> > > > > >
> > > > > > Paul3rd wrote:
> > > > > > >
> > > > > > > Hello, I can't get the following code to execute correctly. It creates a new
> > > > > > > worksheet, but not from a template as I intended.
> > > > > > > Can anyone help?
> > > > > > > >Sub CTMacro()
> > > > > > > >On Error Resume Next
> > > > > > > > Dim ExcelSheet As Object
> > > > > > > >
> > > > > > > >Application.DisplayAlerts = False
> > > > > > > >Set ExcelSheet = CreateObject("Excel.Sheet")
> > > > > > > >Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
> > > > > > > >
> > > > > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > > > > ExcelSheet.Application.Visible = True
> > > > > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > > > > .PasteSpecial xlPasteValues
> > > > > > > >
> > > > > > > > ExcelSheet.SaveAs "C:\CTest.xls"
> > > > > > > > Application.DisplayAlerts = True
> > > > > > > > End With
> > > > > > > > End With
> > > > > > > >End Sub
> > > > > > > Thanks in advance for any help.
> > > > > > > Paul
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Dave Peterson
> > > > > >
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Jan 2008
ps. What's the name of the workbook that holds this code?

Dave Peterson wrote:
>
> How about posting your current version of the code?
>
> Paul3rd wrote:
> >
> > Dave, sorry for the confusion.
> > My original code did create a new workbook.
> > Now, Jan5copytest.xls is open, it has a command button that triggers the
> > module.
> > The module creates a new workbook from the template (CTest.xlt), copies a
> > range to it, saves the new workbook as (CCTest.xls) and then closes it.
> > Which is what I wanted.
> > The module is also closing Jan5copytest.xls which is not what I wanted.
> > I won't use the > character anymore.
> > Paul
> >
> > "Dave Peterson" wrote:
> >
> > > I don't understand.
> > >
> > > I thought you wanted a worksheet added to an existing workbook--not a new
> > > workbook.
> > >
> > > And if Jan5copytest.xls is already open (you used it in your With statement),
> > > why are you trying to open it again.
> > >
> > > And is there a reason you're not copying the code from the VBE and pasting it
> > > into your message.
> > >
> > > To me, those ">" brackets mean that the stuff you posted isn't the same as the
> > > code you're testing.
> > >
> > > Paul3rd wrote:
> > > >
> > > > Hello Dave,
> > > > You are correct, I didn't write the complete path to CTest.xlt.
> > > > I have the code working correctly now (in a new module) except for one small
> > > > thing...
> > > > The Jan5copytest.xls closes after code executes and I want to keep it open.
> > > > (I tried inserting a line Workbook.Open("C:\Jan5copytest') but it didn't work.
> > > >
> > > > >Sub NewModule()
> > > > >Dim MyWB As Workbook
> > > > >
> > > > >Application.DisplayAlerts = False
> > > > >Set MyWB = Workbooks.Add("C:\FolderAppt\CTest.xlt")
> > > > > With Workbooks("Jan5copytest.xls")
> > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > >
> > > > >
> > > > > MyWB.Application.Visible = False
> > > > > With MyWB.Sheets("Sheet1").Range("B2:I2")
> > > > > .PasteSpecial xlPasteValues
> > > > >
> > > > >MyWB.SaveAs ("C:\CCTest.xls")
> > > > >MyWB.Close (True)
> > > > >Workbooks.Open ("C:\Documents and Settings\Administrator\My >Documents\Excel Code Tests\Jan5copytest.xls")
> > > > >Application.DisplayAlerts = True
> > > > > End With
> > > > > End With
> > > > >
> > > > >End Sub
> > > >
> > > > "Dave Peterson" wrote:
> > > >
> > > > > Remove or comment the "on error resume next" line.
> > > > >
> > > > > I bet that it's masking an error.
> > > > >
> > > > > (You sure that C:\cTest.xlt actually exists?)
> > > > >
> > > > > Paul3rd wrote:
> > > > > >
> > > > > > Dave, Thanks for your reply, I changed the code to the following but no new
> > > > > > workbook/worksheet is created.
> > > > > >
> > > > > > >Sub CTMacro()
> > > > > > >On Error Resume Next
> > > > > > > Dim ExcelSheet As Object
> > > > > > >
> > > > > > >Application.DisplayAlerts = False
> > > > > > >Set ExcelSheet = Sheets.Add(Type:="C:\CTest.xlt")
> > > > > > >
> > > > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > > > ExcelSheet.Application.Visible = True
> > > > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > > > .PasteSpecial xlPasteValues>
> > > > > > >
> > > > > > > ExcelSheet.SaveAs "C:\DaveTest.xls"
> > > > > > > Application.DisplayAlerts = True
> > > > > > > End With
> > > > > > > End With
> > > > > > >End Sub
> > > > > >
> > > > > > "Dave Peterson" wrote:
> > > > > >
> > > > > > > Dim ExcelSheet As Object
> > > > > > > set ExcelSheet = sheets.Add(type:="c:\ctest.xlt")
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Paul3rd wrote:
> > > > > > > >
> > > > > > > > Hello, I can't get the following code to execute correctly. It creates a new
> > > > > > > > worksheet, but not from a template as I intended.
> > > > > > > > Can anyone help?
> > > > > > > > >Sub CTMacro()
> > > > > > > > >On Error Resume Next
> > > > > > > > > Dim ExcelSheet As Object
> > > > > > > > >
> > > > > > > > >Application.DisplayAlerts = False
> > > > > > > > >Set ExcelSheet = CreateObject("Excel.Sheet")
> > > > > > > > >Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
> > > > > > > > >
> > > > > > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > > > > > ExcelSheet.Application.Visible = True
> > > > > > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > > > > > .PasteSpecial xlPasteValues
> > > > > > > > >
> > > > > > > > > ExcelSheet.SaveAs "C:\CTest.xls"
> > > > > > > > > Application.DisplayAlerts = True
> > > > > > > > > End With
> > > > > > > > > End With
> > > > > > > > >End Sub
> > > > > > > > Thanks in advance for any help.
> > > > > > > > Paul
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > Dave Peterson
> > > > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
Paul3rd
Guest
Posts: n/a
 
      5th Jan 2008
The name of the workbook that holds this code is Jan5copytest.xls.
This is the current code.
Sub NewModule()
Dim MyWB As Workbook

Application.DisplayAlerts = False
Set MyWB = Workbooks.Add("C:\FolderAppt\CTest.xlt")
With Workbooks("Jan5copytest.xls")
.Worksheets("Sheet1").Range("B2:I2").Copy

MyWB.Application.Visible = False
With MyWB.Sheets("Sheet1").Range("B2:I2")
.PasteSpecial xlPasteValues

MyWB.SaveAs ("C:\CCTest.xls")
MyWB.Close (False)

Application.DisplayAlerts = True
End With
End With

End Sub

"Dave Peterson" wrote:

> ps. What's the name of the workbook that holds this code?
>
> Dave Peterson wrote:
> >
> > How about posting your current version of the code?
> >
> > Paul3rd wrote:
> > >
> > > Dave, sorry for the confusion.
> > > My original code did create a new workbook.
> > > Now, Jan5copytest.xls is open, it has a command button that triggers the
> > > module.
> > > The module creates a new workbook from the template (CTest.xlt), copies a
> > > range to it, saves the new workbook as (CCTest.xls) and then closes it.
> > > Which is what I wanted.
> > > The module is also closing Jan5copytest.xls which is not what I wanted.
> > > I won't use the > character anymore.
> > > Paul
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > I don't understand.
> > > >
> > > > I thought you wanted a worksheet added to an existing workbook--not a new
> > > > workbook.
> > > >
> > > > And if Jan5copytest.xls is already open (you used it in your With statement),
> > > > why are you trying to open it again.
> > > >
> > > > And is there a reason you're not copying the code from the VBE and pasting it
> > > > into your message.
> > > >
> > > > To me, those ">" brackets mean that the stuff you posted isn't the same as the
> > > > code you're testing.
> > > >
> > > > Paul3rd wrote:
> > > > >
> > > > > Hello Dave,
> > > > > You are correct, I didn't write the complete path to CTest.xlt.
> > > > > I have the code working correctly now (in a new module) except for one small
> > > > > thing...
> > > > > The Jan5copytest.xls closes after code executes and I want to keep it open.
> > > > > (I tried inserting a line Workbook.Open("C:\Jan5copytest') but it didn't work.
> > > > >
> > > > > >Sub NewModule()
> > > > > >Dim MyWB As Workbook
> > > > > >
> > > > > >Application.DisplayAlerts = False
> > > > > >Set MyWB = Workbooks.Add("C:\FolderAppt\CTest.xlt")
> > > > > > With Workbooks("Jan5copytest.xls")
> > > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > >
> > > > > >
> > > > > > MyWB.Application.Visible = False
> > > > > > With MyWB.Sheets("Sheet1").Range("B2:I2")
> > > > > > .PasteSpecial xlPasteValues
> > > > > >
> > > > > >MyWB.SaveAs ("C:\CCTest.xls")
> > > > > >MyWB.Close (True)
> > > > > >Workbooks.Open ("C:\Documents and Settings\Administrator\My >Documents\Excel Code Tests\Jan5copytest.xls")
> > > > > >Application.DisplayAlerts = True
> > > > > > End With
> > > > > > End With
> > > > > >
> > > > > >End Sub
> > > > >
> > > > > "Dave Peterson" wrote:
> > > > >
> > > > > > Remove or comment the "on error resume next" line.
> > > > > >
> > > > > > I bet that it's masking an error.
> > > > > >
> > > > > > (You sure that C:\cTest.xlt actually exists?)
> > > > > >
> > > > > > Paul3rd wrote:
> > > > > > >
> > > > > > > Dave, Thanks for your reply, I changed the code to the following but no new
> > > > > > > workbook/worksheet is created.
> > > > > > >
> > > > > > > >Sub CTMacro()
> > > > > > > >On Error Resume Next
> > > > > > > > Dim ExcelSheet As Object
> > > > > > > >
> > > > > > > >Application.DisplayAlerts = False
> > > > > > > >Set ExcelSheet = Sheets.Add(Type:="C:\CTest.xlt")
> > > > > > > >
> > > > > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > > > > ExcelSheet.Application.Visible = True
> > > > > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > > > > .PasteSpecial xlPasteValues>
> > > > > > > >
> > > > > > > > ExcelSheet.SaveAs "C:\DaveTest.xls"
> > > > > > > > Application.DisplayAlerts = True
> > > > > > > > End With
> > > > > > > > End With
> > > > > > > >End Sub
> > > > > > >
> > > > > > > "Dave Peterson" wrote:
> > > > > > >
> > > > > > > > Dim ExcelSheet As Object
> > > > > > > > set ExcelSheet = sheets.Add(type:="c:\ctest.xlt")
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Paul3rd wrote:
> > > > > > > > >
> > > > > > > > > Hello, I can't get the following code to execute correctly. It creates a new
> > > > > > > > > worksheet, but not from a template as I intended.
> > > > > > > > > Can anyone help?
> > > > > > > > > >Sub CTMacro()
> > > > > > > > > >On Error Resume Next
> > > > > > > > > > Dim ExcelSheet As Object
> > > > > > > > > >
> > > > > > > > > >Application.DisplayAlerts = False
> > > > > > > > > >Set ExcelSheet = CreateObject("Excel.Sheet")
> > > > > > > > > >Set ExcelSheet = ExcelSheet.Workbooks.Add("C:\CTest.xlt")
> > > > > > > > > >
> > > > > > > > > > With Workbooks("Copy of ApptDis.xls")
> > > > > > > > > > .Worksheets("Sheet1").Range("B2:I2").Copy
> > > > > > > > > > ExcelSheet.Application.Visible = True
> > > > > > > > > > With ExcelSheet.ActiveSheet.Range("B2:I2")
> > > > > > > > > > .PasteSpecial xlPasteValues
> > > > > > > > > >
> > > > > > > > > > ExcelSheet.SaveAs "C:\CTest.xls"
> > > > > > > > > > Application.DisplayAlerts = True
> > > > > > > > > > End With
> > > > > > > > > > End With
> > > > > > > > > >End Sub
> > > > > > > > > Thanks in advance for any help.
> > > > > > > > > Paul
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > > Dave Peterson
> > > > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Dave Peterson
> > > > > >
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson

>
> --
>
> Dave Peterson
>

 
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
CreateObject John Nurick Microsoft Access 12 20th Apr 2005 12:32 AM
Re: CreateObject david epsom dot com dot au Microsoft Access Forms 1 20th Apr 2005 12:32 AM
Re: CreateObject Tony Toews Microsoft Access Forms 0 19th Apr 2005 04:42 PM
How to CreateObject in C#? sincethe2004 Microsoft ASP .NET 1 13th Jun 2004 03:06 PM
if in asp is CreateObject("Microsoft.XMLHTTP"). Is in asp.net this Server.CreateObject("MSXML2.ServerXMLHTTP") ? Raúl Martín Microsoft ASP .NET 1 13th May 2004 04:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 AM.