Use VB programming to read and write Excel

Updated on technology 2024-03-08
2 answers
  1. Anonymous users2024-02-06

    Hehe, it's too simple, and there are many ways. Here's the simplest example:

    1. Generate objects directly in VB, which can be hidden and opened or displayed.

    2. Then through this Excel object, open the corresponding document or obtain the corresponding data that needs to be calculated, 3. Call VBA in Excel for calculation;

    4. Display the calculation result in Excel.

    To give you a paragraph of my**,** works fine under excel200 xp 2003, after 2003, I haven't tried, but theoretically there should be no problem.

    In the following example, an instance of Excel is launched.

    public sub exc()

    dim exc

    set exc = createobject("")

    In the previous sentence, an excel object was launched.

    open "G: Learn VBA files for Excel data. xls")

    In the previous sentence, use the open method of the Excel sub-object Workbooks to open an XLS file on the G drive.

    true in the previous sentence, this object is displayed. Set to false if you want to run in the background without anyone knowing

    In this part, you can put the ** of the calculation and other operations you want to perform, if you just used false, which is to let the program perform the calculation in the background, then after the calculation is completed, you can = true again to display the result of the calculation.

    set exc = nothing

    In the previous sentence, close Excel

    Or you can use it to close excel

    end sub

    However, when the above ** is actually used, there is a big trouble: if the user has started an excel before running the program generated by vb, then the above ** will generate an excel object, which is easy to have problems in actual operation, so you can also deal with it like the following:

    public sub exc()

    0 on error resume next 'Ignore errors.

    if <>0 then 'If excel is not running.

    end if

    Clear the err object where the error occurred.

    on error goto 0 'Leave the normal error process.

    Here's how to manipulate this excel object to achieve your goals.

    end sub

    As for how to calculate after starting excel, because the landlord you didn't give an example, I don't know what kind of calculation you want to perform, so I can't give you **. However, for the usual calculation, you can manually operate the calculation steps in Excel, and at the same time use the function of "recording macro" to record the calculation process, and then view the macro, and you can get what you want. Change it a little more.,You can copy it to the above ** in the middle and use it normally.。。

    Hehe, call it a day

  2. Anonymous users2024-02-05

    For example, VBA does just that.

Related questions
25 answers2024-03-08

dim xlbook as

dim xlsheet as >>>More

13 answers2024-03-08

It can be done. You have to call the API to lock the excel object in the process. Then, you can directly obtain the process ID for listening and other operations. It's a bit difficult.

9 answers2024-03-08

Referencing the Microsoft Excel Type Library in the project: >>>More

22 answers2024-03-08

The data is stored in binary form in the computer, the decimal integer can be accurately converted to binary form, and there will be an error when the decimal number of the non-integer number is converted to a single-precision number or a double-precision number, and the non-integer number is used as a cyclic variable, and the step is also a non-integer number, so the number of cycles may not be as desirable. Therefore, you should avoid using non-integer numbers to control the loop. >>>More

13 answers2024-03-08

Picturebox also works well

Generally, the graphics of each chess piece are collected in a single diagram. >>>More