Home > Software engineering > About VB use common dialog component problem, a great god answers.
About VB use common dialog component problem, a great god answers.
Time:09-20
Specific situation is like this, I want to write a program that need to open an existing excel spreadsheet to calculate, and the results generated new excel and save, At first I was written like this:
Dim excel_App As Excel. Application Dim excel_Book As Excel. The Workbook Dim excel_sheet As Excel. The Worksheet The Set excel_App=CreateObject (" Excel. Application ") Excel_App. Visible=False Set excel_Book=excel_App. Workbooks. Open (App) Path + "\ A file. XLSX") The Set excel_sheet=excel_Book. Worksheets (" Sheet1 ") Dim As Integer I Dim j As Integer Dim matrix (1 To 10, 1 To 12) As an Integer Dim a (1 To 10, 1 To 12) As an Integer Dim b (1 to 10, 1 to 12) as an integer For I=1 To 10 For j=1 To 12 A (I, j)=excel_sheet. Cells (I + 1, j + 1) B (I, j)=a (I, j) + 3 Excel_sheet. Cells (I + 1, j + 1)=b (I, j)
Excel_Book_b. SaveAs FileName:=App. Path + "B file. XLSX " The Set excel_sheet=Nothing Excel_App. ActiveWorkbook. Close SaveChanges:=False The Set excel_Book=Nothing Excel_App. Quit The Set excel_App=Nothing
But I find that writing, it is necessary to put the file into the program with the directory, is not very convenient, So I just want to use the common dialog, each time you run the program to choose of excel, read the application to the data, finally, operations, reoccupy file dialog stored in a designated location, could you tell me how to write the program?
CodePudding user response:
You already know the vb common dialog, baidu should have a lot of examples:)
CodePudding user response:
Comdlg. ShowOpen Comdlg. The FileName is what you want