Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

Excel Macro: Open Sheet in Background and Execute Analysis in Background Sheet

I am relatively new to the true power in Excel - Macros/VBA and have been tasked to set up the financial model for a million dollar project. I am able to set everything up and have it run smoothly, but there's too much manual input involved. I would like to seek simplification through the power of VBA.

This is my dilemma:

  1. I need to be able to individually double-click on a specific set of cells (in a Row), which will open up a file window that allows me to select a EXL file.

  2. Once I select the file, that file should be preferably opened in a temp status (not visible, but I can run functions and pull info from it).

  3. I will then need the macro to go into that opened sheet, conduct a simple SUMIFS function, and record the outcome in a column of the current sheet I'm working from.

I've been doing some Excel tutorial on Lynda in hope to seek the answers there, but I think the complexity of this request demands the knowledge of a true master.

Any help will be greatly appreciated! I would imagine this could be a nice little challenge for those who seek it :)

Sincere thanks,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this:

Dim appExcel        As Excel.Application
Set appExcel = CreateObject("EXCEL.Application")

Dim wkbk            As Excel.Workbook
Set wkbk = appExcel.Workbooks.Open(sPathSrc, , False, , , sPassword)

' do EXCEL work here

If Not wkbk Is Nothing Then wkbk.Close True
Set wkbk = Nothing

If Not appExcel Is Nothing Then
    appExcel.DisplayAlerts = False
    appExcel.Quit
End If
Set appExcel = Nothing

This code is from an ACCESS application that invoked EXCEL to print some reports. I found it necessary to sprinkle some DOEVENTS calls around, but it was all a while ago; some details escape me at this moment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...