Run a program with data from another workbook - vba

I previously created a VBA program that launched the form from a command button. Sheet 1 was the command button and Sheet 2 was the data that the program referenced. I want to put the data into a separate workbook so that I can put it in a shared drive that can be run on other machines, as well as giving me the option to update the data in the workbook (all separate from the original program). I also think this would make the program faster and much more lightweight, so it doesn't have to open up all the data in Sheet 2 along with it. How could I open the data workbook in the background and be able to reference it in my code?

Related

Make VBA automatically accept opening writeprotected files

I have a chunck of VBA code, which opens 2 files, copy the content in each, and paste that into a third file.
The problem is, that the two files (lets say "alm" and "fiber") often are used by other users, thus when i use Set alm = Workbooks.Open(alm_path) I get an error, since Excel cannot open it. I assume it is due to the file being opened by another user, and I then have to open it as write protected. Is there any smart way to do so? I am fairly new to VBA code
As mentioned in the comments you can open the workbook as ReadOnly, an example below:
Dim alm As Workbook
Set alm = Workbooks.Open(Filename:=alm_path, ReadOnly:=True)

Communication between 2 excel workbooks that opened from different PC

I have multiples excel workbooks that will be stored in a share drive and each of them will be opened from different PCs on the same time.
ie:
wb1 open from PC1.
wb2 open from PC2.
wb3 open from PC3.
...
Users will update value in cell A1 for each workbook from different PCs. And there will be a main workbook which store the value from each workbooks.
After users updated the value, I want to create a "send" button on each excel workbook to send the value to the main workbook and the main workbook will display the value from different workbooks once user click on the "send" button.
Also, I want to have a "revise" button at the main workbook. When the button is clicked, the values in cell A1 will be cleared and cell A2 will show "Please Revise" for all workbooks.
Is this possible? As all the workbooks are opened at the same time from different PC.
As I understand it, what you are asking for is not possible with current Office editions. At my previous job we had Excel files on a shared drive that were accessed everyday by multiple computers/users. One user cannot make edits to an Excel file while it is in use by another user.
If you want multiple users to be able to make edits to a live document at the same time, you might try Google sheets instead. They have an application very similar to Excel that will probably support what you are trying to do.

Blue Prism - Running Multi Macros in a Process

I'm running into an instance error when trying to run 2 VBO Excel macros in a process.
My process is as follows (please note I'm running 2 macros back to back): Create Instance - Open Workbook - Activate Worksheet - Run Macro - Create Instance - Open Workbook - Activate Worksheet - Run Macro
Error Received for the second pass:
Workbook Not Found : Workbook named: Select Clients.xls not found in instance: 0
Any thoughts?
The reason you're seeing this error is due to the way Excel "instances" are logically laid out when launched by Blue Prism. TL;DR: Don't use the Create Instance action more than once, instead open all your workbooks in the same instance.
When creating an Excel instance, Blue Prism assigns a numeric handle variable to that instance. Using that handle, you'll only be able to access workbooks created in that instance. Logically, each instance would have it's own separate workbooks, worksheets, etc.:
Because Create Instance creates a completely separate instance of Excel, you won't be able to access workbooks created within the first instance. Instead of spamming Create Instance, use Open Workbook and pass in the same handle you were originally assigned. From there, you'll be able to access whatever you've opened previously.

Vba project cant open if excel is already running

I want to open my vba project from my USB stick, but if excel is already running with some other sheets (with new data) it won't open my vba project.
It only opens when my other excel sheets are closed or saved.
What can I do?
Is it possible to make a msgbox for telling the user that he must first save other excel projects (when I want to open the project while other excel sheets are not saved) ?
Note that Excel allows a filename only once to be opened, independent of where the files are placed. So C:\Documents\mysheets.xls and F:\memstick\mysheets.xls have the same name and only one can be open at the same time.
Have you tried to open a second Excel instance?
1. Open Excel with start/programs/microsoft excel or wherever
2. Open your macro in that second instance or just pull it into that new excel form.
should work i think...

Keep getting Excel and Windows Prompts while working with Interop Services

All of this is being done in VB.NET using the Excel 14.0 Interop Services
I am at my wits end. I keep getting prompts from windows and excel during the middle of a batch run.
The program i have takes in a workbook with batch records, then runs simulations on each batch record, then writes the results back out to the excel file.
The steps:
Open workbook
check to see if workbook is already in use by another program.
if it is in use. we try to close the workbook. then we wait for a set amount of time before trying again.
if the workbook is not in use we continue.
Get the contents
Mark the records as being processed
save and close the file.
process the records.
do the same process above to open the workbook.
save the results to the workbook.
close the workbook.
loop these processes until all the records have been simulated.
Ok the problems that can occur:
Workbook is already in use or two programs are trying to interact with the save workbook at the same time.
Ok now for the problem that i am having.
When the workbook is being interacted with by two programs at the same time. a prompt will show saying the file is currently in use.
another problem that happens that i can't explain is excel will show a prompt saying that the file is now ready to be modified with the options read-write, notify, cancel.
I need to find a way to handle these prompts programmatically.
If any one can point me in the right direction I would be very greatful.
You can prevent the prompts from appearing by setting:
Dim xlApp As Excel.Application = New Excel.Application
xlApp.DisplayEvents = False
But I've not found a way to actually "catch" the prompts and do something useful. I've noticed that often if Interop cannot get hold of a file then it will throw an exception. The exception rarely contains any way to distinguish what the actual error is, but you can sometimes work it out based on what could happen at that point.