January 5th, 2000, 09:24 AM
Help! I need to know if Visual Basic is as easy as I was told. I need to create a program that will take approx.
250 hours of work into a one click easy to use program. Basically what I need to know is how do I get Visual
Basic to open Word and Excel and PowerPoint and perform the necessary functions. I know how to create
macros. I am in my first year of computer programming and anxious to get this project going? Thanks
January 5th, 2000, 10:36 AM
Well, not to sound unhelpful, but if all you want to do is control Office apps, I would recommend writing VBA code (aka Macros) in the respective apps. Visual Basic can control these applications though...but it's alot easier to just write VBA code. For example...to control an Excel spreadsheet try this code:
Sub WriteToExcel()
Dim objExcel as Object
Dim objSheet as Object
'Create objects to use
set objExcel = CreateObject("Excel.Sheet")
set objSheet = objExcel.Application.Worksheets("Sheet1")
'Change the name of Sheet1 from "Sheet1"(default name) to "Test Sheet"
objSheet.Name = "Test Sheet"
'Put some text in row 1, cell 1 (which equates to cell A1)
objSheet.Cells(1,1) = "Hello World!"
'Save the spreadsheet to the applications directory and
'name it "Test.xls"
objSheet.SaveAs App.Path & "\Test.xls"
'Destroy object variables
set objExcel = nothing
set objSheet = nothing
End Sub
All the above code will run invisible to the user. That is, you won't actually see Excel popup and do all the work. You could make Excel visible by adding the line
objExcel.Application.Visible = true
Now open the file Test.xls in Excel and see that cell A1 has the text
"Hello World" in it, and the name of the sheet on the sheet tab(bottom of screen usually) says "Test Sheet". Alot more work than just using VBA.
Hope that helps,
Rippin