Sinbad
Sinbad

Reputation: 47

How to open a file from a userform and modify it with the userform open

I have a userform with checkboxes, textfields and the normal usual things on it, including a button that I'd like to use to open a excel spredsheet. This is easy enough to do:

Private Sub CMB2_Click()
    Workbooks.Open Filename:="G:\Formular.xlsm"
End Sub

When doing this though, the file can not be worked on; in other words, it is not active. The from is active, and until the form is closed or cancelled, the file is locked. I call it locked for a lack of a better description.

If I make the form modeless, all fields in the form loose their function, except the buttons but at least I can work in the opened spreadsheet.

UserForm1.Show vbModeless

How can I get both? I want to work in the opened spreadsheet and continue on the form when done.

Upvotes: 1

Views: 10651

Answers (1)

Hiten004
Hiten004

Reputation: 2481

you have to open other files in new excel instance. following code will do this for you

Dim xlApp as Excel.Application
set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open FileName:="G:\Formular.xlsm"

Upvotes: 3

Related Questions