Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript & Excel Files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi Ladiez & Gentz,

this is an example out of my Learn Scripting In 2 Hours Book (Yeah Right)

it opens excel and then creates a new workbook and changes some of the cell properties and enters some info

but what i want is to open excel and then OPEN a workbook - anyone got any idea on how to

thanks in advance

Alex T
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

L_Welcome_MsgBox_Message_Text = "This script will display Windows Scripting Host properties in Excel"
L_Welcome_MsgBox_Title_Text = "Windows Scripting Host & Excel"

'Excel Sample

Dim objXL
Set objXL = WScript.CreateObject("Excel.Application")

objXL.Visible = True

objXL.Workbooks.Add

objXL.Columns(1).ColumnWidth = 20
objXL.Columns(2).ColumnWidth = 30
objXL.Columns(3).ColumnWidth = 40

objXL.Cells(1, 1).Value = "Property Name"
objXL.Cells(1, 2).Value = "Value"
objXL.Cells(1, 3).Value = "Description"

objXL.Range("A1:C1").Select
objXL.Selection.Font.Bold = True
objXL.Selection.Interior.ColorIndex = 1
objXL.Selection.Interior.Pattern = 1 'xlSolid
objXL.Selection.Font.ColorIndex = 2

objXL.Columns("B:B").Select
objXL.Selection.HorizontalAlignment = &hFFFFEFDD 'xlLeft

Dim intIndex
intIndex = 2

Sub Show(strName, strValue, strDesc)
objXL.Cells(intIndex, 1).Value = strName
objXL.Cells(intIndex, 2).Value = strValue
objXL.Cells(intIndex, 3).Value = strDesc
intIndex = intIndex + 1
objXL.Cells(intIndex, 1).Select
End Sub

'Show WScript Properties
Call Show("Name", WScript.Name, "Application Friendly Name")
Call Show("Version", WScript.Version, "Application Version")
Call Show("FullName", WScript.FullName, "Application Context: Fully Qualified Name")
Call Show("Path", WScript.Path, "Application Context: Path Only")
Call Show("Interactive", WScript.Interactive, "State Of Interactive Mode")

'Show Command line Arguments
Dim colArgs
Set colArgs = WScript.Arguments
Call Show("Arguments.Count", colArgs.Count, "Number of command line arguments")

For i = 0 To colArgs.Count - 1
objXL.Cells(intIndex, 1).Value = "Arguments(" & i & ")"
objXL.Cells(intIndex, 2).Value = ColArgs(i)
intIndex = intIndex + 1
objXL.Cells(intIndex, 1).Select
Next

'Welcome
Sub Welcome()
Dim intDoIt

intDoIt = MsgBox(L_Welcome_MsgBox_Text, vbOkCancel + vbInformation, L_WelcomeTitleText)
If intDoIt = vbCancel Then
WScript.Quit
End If
End Sub


 
Alex

Try this. I've got this linked to a button which opens Excel and then a workbook stored on my h drive. Change the file location for your workbook and it should work.

Good luck

John B

<INPUT id=button1 name=button1 type=button value=Button>
<SCRIPT LANGUAGE=&quot;VBScript&quot;>

sub button1_onclick()

dim app
set app = createobject(&quot;EXCEL.Application&quot;)

app.Visible = true


app.workbooks.open&quot;h:\cobain\takeup\working\common\excel\adjinp.xls&quot;




app.UserControl = true

end sub
</SCRIPT>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top