|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Accessing an open workbook from a VB appworksheet called "Basic". 'Start the excel COM and make it visible Set objExcel = GetObject("", "excel.application") objExcel.Visible = False 'Start a workbook. Set objWorkbook = objExcel.Workbooks.Add objWorkbook.SaveAs "DP_RBF.xls" 'Turn off the alerts, otherwise user will have to confirm my actions. objExcel.DisplayAlerts = False 'Ensure there is only one worksheet. Do While objWorkbook.Worksheets.Count > 1 Set objWorksheet = objWorkbook.Worksheets.Item(objWorkbook.Worksheets.Count) objWorksheet.Delete Loop 'Rename the remaining sheet as "Results" Set objWorksheet = objWorkbook.Worksheets.Item("Sheet1") objWorksheet.Name = "Basic" Now to my problem. With a different VB app, I want to read some of the information from the worksheet "Basic" into variables in my VB app and do some calcs with them. I can't seem to figure out how to get a handle on the worksheet from my second VB app. I know it's something really silly but I can't find my problem. Anyone want to give me a hand. Thanks. Jules -- PhD student Industrial Engineering "Jules Comeau" <JulesCom***@discussions.microsoft.com> wrote in message objExcel.SheetsInNewWorkBook = 1news:582CE8A6-B8B7-4386-B26E-CB9240B020AE@microsoft.com > I am using a VB app to open a workbook called "DP_RBF" that includes a > worksheet called "Basic". > > 'Start the excel COM and make it visible > Set objExcel = GetObject("", "excel.application") > objExcel.Visible = False > > 'Start a workbook. > Set objWorkbook = objExcel.Workbooks.Add <cut out the code to delete extra worksheets>> objWorkbook.SaveAs "DP_RBF.xls" > 'Rename the remaining sheet as "Results" Have you saved and closed the workbook from the first app? If so then you> > Set objWorksheet = objWorkbook.Worksheets.Item("Sheet1") > objWorksheet.Name = "Basic" > > > Now to my problem. With a different VB app, I want to read some of > the information from the worksheet "Basic" into variables in my VB > app and do some calcs with them. I can't seem to figure out how to > get a handle on the worksheet from my second VB app. I know it's > something really silly but I can't find my problem. can open the workbook from the second app. If not do you mean that you want 2 apps to share the same workbook and worksheet at the same time? If so then I'd look for some other option as you are going to have a *very* difficult time ensuring that you actually have the same worksheet open, specially if multiple Excel instances are running. -- Reply to the group so all can participate VB.Net: "Fool me once..."
Show quote
Hide quote
"Bob Butler" wrote: thanks this is much simpler> "Jules Comeau" <JulesCom***@discussions.microsoft.com> wrote in message > news:582CE8A6-B8B7-4386-B26E-CB9240B020AE@microsoft.com > > I am using a VB app to open a workbook called "DP_RBF" that includes a > > worksheet called "Basic". > > > > 'Start the excel COM and make it visible > > Set objExcel = GetObject("", "excel.application") > > objExcel.Visible = False > > > > 'Start a workbook. > > > objExcel.SheetsInNewWorkBook = 1 Show quoteHide quote > > Set objWorkbook = objExcel.Workbooks.Add I guess I wasn't really clear here. I have a VB app that has two command > > objWorkbook.SaveAs "DP_RBF.xls" > > <cut out the code to delete extra worksheets> > > > 'Rename the remaining sheet as "Results" > > > > Set objWorksheet = objWorkbook.Worksheets.Item("Sheet1") > > objWorksheet.Name = "Basic" > > > > > > Now to my problem. With a different VB app, I want to read some of > > the information from the worksheet "Basic" into variables in my VB > > app and do some calcs with them. I can't seem to figure out how to > > get a handle on the worksheet from my second VB app. I know it's > > something really silly but I can't find my problem. > > Have you saved and closed the workbook from the first app? If so then you > can open the workbook from the second app. If not do you mean that you want > 2 apps to share the same workbook and worksheet at the same time? If so > then I'd look for some other option as you are going to have a *very* > difficult time ensuring that you actually have the same worksheet open, > specially if multiple Excel instances are running. buttons on the form (not a separate app). One of the buttons opens the spreadsheet and populates it with info which the user can change if they wish. The second button on the form should read that user info and use it to do some cals. Are you saying that it would be easier just to close the Excel app the first time while saving the file and reopen it again when I need the info in the worksheet? Thanks for your help!! Jules Show quoteHide quote > -- > Reply to the group so all can participate > VB.Net: "Fool me once..." > >
How big of a difference between VB 6 and .net
Flowchart software that supports top down development? Running under Scheduler shorts and longs INT() vs CInt() Best way to build a Code Library Run-time error '13': Type mismatch Compile Error Argument not optional for Parameter.Append Error deleting Word temp files Number of Controls on the Form |
|||||||||||||||||||||||