100%(2)2 out of 2 people found this document helpful
This preview shows page 514 - 517 out of 547 pages.
The following code will open a new instance of PowerPoint and display a presentation. Whenone stops the presentation (by pressing ESC, then PowerPoint stays open:SubOpen_And_Run_PPT1()DimPPtObjectAs ObjectDimpptPresentationAs ObjectSetPPtObject =CreateObject("PowerPoint.Application")PPtObject.Visible=TrueSetpptPresentation = _PPtObject.Presentations.Open_("C:\temp\presentation example.ppt")PPtObject.ActivePresentation.SlideShowSettings.RunEnd SubIf you want PowerPoint to close after the presentation, then use code like the following:.SubOpen_And_Run_PPT_and_Close()DimPPtObjectAs ObjectDimpptPresentationAs ObjectSetPPtObject =CreateObject("PowerPoint.Application")PPtObject.Visible=TrueSetpptPresentation = _
515PPtObject.Presentations.Open_("C:\temp\presentation example.ppt")PPtObject.ActivePresentation.SlideShowSettings.RunWhilePPtObject.SlideShowWindows.Count= 1DoEventsWendPPtObject.ActivePresentation.ClosePPtObject.QuitEnd Sub33.18 Displaying A DOS WindowThe following will display a DOS window:SubGiveMeDos()DimtaskIDtaskID =Shell("Command.com", 1)End Sub33.19 Getting Data From AccessOne of the most popular ways to do this is to use ADO or DAO to get the data and then to useExcel's CopyFromRecordset method to plop the data down. In Excel 97 and prior, theCopyFromRecordset method only supports DAO recordsets. However, Excel 2000 now supportsADO recordsets.The following illustrate two methods of getting data into Excel from Access:SubGetDataWithDAO()DimdbAsDAO.DatabaseDimrstAsDAO.RecordsetSetdb =OpEndatabase("C:\My Documents\SalesDb.mdb")Setrst = db.OpenRecordset("SalesData")Range("A1").CopyFromRecordSetrstEnd SubSubGetDataWithADO()DimcntAs New ADODB.ConnectionDimrstAs New ADODB.Recordsetcnt.Open"Provider=Microsoft.Jet.OLEDB.4.0;" & _"Data Source=C:\My Documents\SalesDb.mdb;"rst.Open"Select * From SalesData", cntRange("A1").CopyFromRecordSetrstEnd SubIf you need to get data from Access while running a Visual Basic macro, also check thefollowing Microsoft Internet pages for information of using DAO to get data from Access.This page has a number of articles and a help file you can download.
516Microsoft knowledge base article Q149254 also gives an example of how to return DAO queryresults directly to a list box in Excel.The following is a posting on the Excel Visual Basic user group that gives some additionalexamplesQuestion asked: "Looking for some advice relating to connecting to an Access database withinexcel"Response:If it's not a secured database, then you can simply callsetrs = DBEngine.Opendatabase(DBPath, Options)- check the help file for details. You will, of course, have to select one of the DAO libraries in theVBA references dialog first - 3.5 is the recommended one, assuming you're on Office 97.If it is secured, you need to mess about with userid's and passwords.