Open Excel File with VBA


I am trying to open an Excel file with VBA.  My code looks like this so far :

Set appXL = New Excel.Application
Set xlWB = appXL.Workbooks.Open(strPath)
xlWB.Application.Visible = True

It opens and it even edits the way I want it to but I cant save it.  I noticed that when it opens the Excel it says read-only.  But when I open that file normally it does not say read only.  How do I change this?  Thanks

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LucasMS Dynamics DeveloperCommented:
If you already have the file open before you open it via your code, it will always be read only.

Set xlWB = appXL.Workbooks.Open(strPath),,true
'sets it to read only

Set xlWB = appXL.Workbooks.Open(strPath),,false
'not read only


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LucasMS Dynamics DeveloperCommented:
You should also look into "late binding" so that your app will work in all versions of excel.

In the above code you have to also:

set xlapp = Nothing
set xlWb = Nothing
Here is an example that does the same as above.

Dim pathname as string
dim myExcel as object

pathname = "C:\myExcelfile.xls"

set myExcel = CreateObject("Excel.Application") pathname,,true
myexcel.visible = true

set my excel = nothing
lebeau26Author Commented:
Ugh, I so dumb, I had it open.  Thanks
LucasMS Dynamics DeveloperCommented:
No problem ;-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.