CreateObject("Excel.Application") 
Author Message
 CreateObject("Excel.Application")

I want to Open an Excel File on the server and feed it data from a web form
submission. I guess I would start with the following, but I don't know how
to feed data into the different cells. Any suggestions or reading material
on this?

Set ExcelApp = CreateObject("Excel.Application")

ExcelApp.Documents.Open("C:\folder\file.xls")



Sat, 08 Nov 2003 23:55:19 GMT  
 CreateObject("Excel.Application")
Here's a script I use to stuff values into an existing spreadsheet.

'
'
'  Name:
'
'
'
'    TrendTemp.vbs
'
'
'
'  Description:
'
'
'
'    Show how accurate the weather forecast is by comparing the hourly
temperature readings  '
'    for Winnipeg against the actual values. The actual data consists of the
24 hour values  '
'    from yesterday. The hourly forecasts for the 48 hours prior to that are
compared to     '
'    the actual data. The output is in the form of an Excel spreadsheet.
'
'
'
'  Audit:
'
'
'
'    2000/12/15  jdeg  added TempRange to more easily modify all charts
'
'    2000/12/08  jdeg  original code
'
'
'

TempRange = 10       'vertical axis range is from -TempRange to +TempRange

set wso = CreateObject("Wscript.Shell")
set env = wso.Environment("User")

'run the date picker program

if wso.run("\\ems-nt1\utilities\pickdate.exe -1D Trend what day?",,true) = 0
then

   PickDate = env("PickDate")

   'if the user really picked a date (instead of hitting the close button)

   if len(PickDate) = 0 then
      set env = Nothing
      set wso = Nothing
      Wscript.Quit
   end if

   PickDate = cDate(PickDate)

   if Pickdate >= Date() then
      wscript.Echo "The most recent date you can pick is yesterday"
      set env = Nothing
      set wso = Nothing
      wscript.Quit
   end if

end if

'cols is used to convert column numbers to names

cols = Split("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"," ")

ConnectionString = "Provider=SQLOLEDB.1;" _
                 & "Data Source=wpg-dbserver-09;" _
                 & "User ID=sa;Initial Catalog=weather;" _
                 & "Persist Security Info=False;"

set conn = CreateObject("ADODB.Connection")
set robj = CreateObject("ADODB.RecordSet")
Set xcel = CreateObject("Excel.Application")

conn.Open ConnectionString

'set the spreadsheet properties

with xcel
   .Application.DisplayAlerts = False
   .Visible = true
   .Workbooks.Open "\\ems-nt1\weather\TrendTemp.xls"
end with

for s = 1 to 4
   for c = 1 to 4
      xcel.WorkSheets(s).ChartObjects(c).Chart.Axes(2).MinimumScale
= -TempRange
      xcel.WorkSheets(s).ChartObjects(c).Chart.Axes(2).MaximumScale =
+TempRange
   next
next

xcel.WorkSheets("RawData").Select

filedate = (PickDate + 1) & " 05"
fcstdate = PickDate
basedate = fcstdate & " 00:01"

'get the actual data for all hours for yesterday

if GetData(fcstdate,filedate) then

   xcel.Cells(52,2) = "Actuals are for " & fcstdate

   'put the actuals into the first data row of the spreadsheet

   for hh = 1 to 24
      xcel.Cells(2,hh+1) = robj(hh+1)
   next

   row = 2

   'get the forecast data for each hour for the previous two days

   for offset = -1 to -48 step -1

      row = row + 1

      filedate = DateAdd("h",offset,basedate)
      filedate = Left(filedate,10) & " " &
Left(FormatDateTime(filedate,4),2)

      if GetData(fcstdate,filedate) then
         for hh = 1 to 24
            xcel.Cells(row,hh+1) = xcel.Cells(2,hh+1) - robj(hh+1)
         next
      end if

   next

end if

robj.Close: set robj = Nothing
conn.Close: set conn = Nothing

set xcel = Nothing
set env  = Nothing
set wso  = Nothing

Function GetData ( fcstdate, filedate )

   dim cmd

   cmd = "select * from trendtemp" _
       & " where FcstDate = '" & fcstdate & "'" _
       & "   and FileDate = '" & filedate & "'" _
       & " order by FileDate"

   'wscript.Echo cmd

   if robj.State = 1 then robj.Close
   robj.Open cmd, conn, 1
   GetData = not robj.EOF

End Function



Sun, 09 Nov 2003 00:53:22 GMT  
 CreateObject("Excel.Application")
Thanks that sample got me over the edge, and I'm now doing just what I need
to do.

However I have a new question. As in your sample below ".Visible = true",
only makes Excel visible in the Task Manager applications section, but not
visible within windows. Is this normal behavior?

Quote:
> with xcel
>    .Application.DisplayAlerts = False
>    .Visible = true
>    .Workbooks.Open "\\ems-nt1\weather\TrendTemp.xls"
> end with



Sun, 09 Nov 2003 20:56:17 GMT  
 CreateObject("Excel.Application")
Strange - when I execute .Visible = true, it makes the spreadsheet visible
on my desktop.


Quote:
> Thanks that sample got me over the edge, and I'm now doing just what I
need
> to do.

> However I have a new question. As in your sample below ".Visible = true",
> only makes Excel visible in the Task Manager applications section, but not
> visible within windows. Is this normal behavior?

> > with xcel
> >    .Application.DisplayAlerts = False
> >    .Visible = true
> >    .Workbooks.Open "\\ems-nt1\weather\TrendTemp.xls"
> > end with



Sun, 09 Nov 2003 21:41:35 GMT  
 CreateObject("Excel.Application")
I guess that's good to know. I don't need to see it for this project so it's
not a problem. Maybe if I add shell commands as well it would work.



Quote:
> Strange - when I execute .Visible = true, it makes the spreadsheet visible
> on my desktop.



> > Thanks that sample got me over the edge, and I'm now doing just what I
> need
> > to do.

> > However I have a new question. As in your sample below ".Visible =
true",
> > only makes Excel visible in the Task Manager applications section, but
not
> > visible within windows. Is this normal behavior?

> > > with xcel
> > >    .Application.DisplayAlerts = False
> > >    .Visible = true
> > >    .Workbooks.Open "\\ems-nt1\weather\TrendTemp.xls"
> > > end with



Sun, 09 Nov 2003 23:04:11 GMT  
 CreateObject("Excel.Application")
Try the UserControl property of the Excel application object.  The
following is from the VBAXL9.CHM help file for Excel2000:

UserControl Property

True if the application is visible or if it was created or started by
the user. False if you created or started the application
programmatically by using the CreateObject or GetObject functions, and
the application is hidden. Read/write Boolean.

Remarks

When the UserControl property is False for an object, that object is
released when the last programmatic reference to the object is released.
If this property is False, Microsoft Excel quits when the last object in
the session is released.

Good Luck !!

Quote:

> I guess that's good to know. I don't need to see it for this project so it's
> not a problem. Maybe if I add shell commands as well it would work.



> > Strange - when I execute .Visible = true, it makes the spreadsheet visible
> > on my desktop.



> > > Thanks that sample got me over the edge, and I'm now doing just what I
> > need
> > > to do.

> > > However I have a new question. As in your sample below ".Visible =
> true",
> > > only makes Excel visible in the Task Manager applications section, but
> not
> > > visible within windows. Is this normal behavior?

> > > > with xcel
> > > >    .Application.DisplayAlerts = False
> > > >    .Visible = true
> > > >    .Workbooks.Open "\\ems-nt1\weather\TrendTemp.xls"
> > > > end with



Mon, 10 Nov 2003 06:09:08 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Set xLApp = CreateObject("Excel.Application")

2. Server.CreateObject("Excel.Application")

3. CreateObject("Excel.Application") Fails on NT

4. CreateObject("Excel.Application") Error

5. CreateObject("Excel.Application")

6. CreateObject("Excel.Application") problem

7. CreateObject("Excel.Application")

8. CreateObject("excel.application", "myremotecomp") dosent work

9. CreateObject("excel.application", "myremotecomp") dosent work

10. CreateObject("Excel","//server"), MsgBox output

11. CreateObject("Excel","//server"), MsgBox output

12. GetObject("","InternetExplorer.Application") fails in Excel VBA

 

 
Powered by phpBB® Forum Software