p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

vb_howto thread: Export to predefine excel file


Message #1 by rgallegos@v... on Mon, 28 May 2001 16:04:23
	Wow.  I'm just a regular code thief.  I stole this from the VBPro mailing
list seconds ago for a VBPro database mailing list question, and here it is
again (still in my clipboard buffer).  This is an example of using OLE
Automation with Excel:

-
Dim xlShell
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
nWorkSheetCtr = 0
For i = 1 To 4
nWorkSheetCtr = nWorkSheetCtr + 1
xlBook.Worksheets.Add
Set xlSheet = xlBook.Worksheets(nWorkSheetCtr)


xlSheet.Cells(1, 1) = "TEST REPORT SYSTEM"
xlSheet.Cells(2, 1) = "SAMPLE REPORT"
xlSheet.Cells(3, 1) = "Run Date/Time: " & strDateTime

xlSheet.Cells(6, 1) = "NAME" & Trim(Str(i))
xlSheet.Cells(6, 2) = "POSITION"
Next i


cFileName = "c:\temp\test.xls"
xlBook.SaveAs cFileName
xlBook.Close
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

xlShell = Shell("C:\Program Files\Microsoft Office\Office\Excel.exe " +
cFileName, vbNormalFocus)
-

	HTH.

? Chuck

> -----Original Message-----
> From: rgallegos@v... [mailto:rgallegos@v...]
> Sent: Monday, May 28, 2001 4:04 PM
> To: VB_Howto
> Subject: [vb_howto] Export to predefine excel file
>
>
> Hello.
>
>
> I know how to export data to excel directly.
>
> But I need export to predefine excel file (with headers, vertical and
> horizontal lines, colors).
>
> My original data are just in a one column and several rows.
>
> What it?s better o more easily to use?
> Export directly my data to predefine excel file?, or Use my first excel
> file to export to a predefine file ?
> But I don?t how make this? Somebody have an idea, some piece of code ?
>
>
> Your help it?s very appreciate for me.
> Thanks in advance
>
>
> RGH
>


  Return to Index