Excel VBA - UsingVBA to create a new, formatted workbook

后端 未结 4 1783
耶瑟儿~
耶瑟儿~ 2021-01-25 06:52

I\'m trying to write the last part of my program and I need to pull data from an Access document and print it into a new Workbook.

To start, I will be taking the names o

4条回答
  •  日久生厌
    2021-01-25 07:39

    You don't give a lot of details, so I can't give you a lot of details in return. But here's how I would do it:

    1. Create a new workbook manually with two sheets
    2. On one sheet, add an External Data table that returns a list of supplier's name like SELECT SupplierName FROM tblSuppliers WHERE Active=True; or something like that.
    3. Create a workbook-level named range that dynamically expands with that query table
    4. On the second sheet, add an External Data table like SELECT * FROM Orders WHERE SupplierName=? (This will be a parameter query). Start that external data table in row 3
    5. I row, put a combobox box that points back to the supplier list.

    Now the VBA is simple

    ThisWorkbook.RefreshAll
    

    Instead of one sheet per supplier, you'll have one sheet on which you can change the supplier. Here are the skills you'll need

    • Create an external data table
    • Create a parameter query (old reference http://www.dicks-clicks.com/excel/ExternalData6.htm)
    • Create dynamically expanding range name
    • Add a combobox or data validation that points to a range on a different sheet
    • That SQL above is obviously not right, but I assume you can write the correct SQL statement

    You should be able to find details on all that, but if not, post another question.

提交回复
热议问题