ChDir Not Working Properly in Excel

I want to open a workbook in one folder, and then use a command button to have a completed worksheet saved to a different folder.  The filename is based on the contents of two cells in the worksheet.  Here is the code that I am using for the command button.

ChDir "\\lpofs01\groups\Engineering\LAB\MI Calculations for Offspec Types"
    ActiveWorkbook.SaveAs Filename:= _
    Range("C3") & "_" & Range("C5") & "_MI Calc", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

My problem is that the file will save in the folder that the worksheet is opened, not the folder that I designate in the ChDir statement.

I am puzzled because I have other worksheets that I do the same thing and they work fine.

Thanks for the help.
Steve LowryPrincipal ChemistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Roy CoxGroup Finance ManagerCommented:
Are you sure the entries in the cells are correct?
0
Martin LissOlder than dirtCommented:
No need to ChDir

ActiveWorkbook.SaveAs Filename:= _
"\\lpofs01\groups\Engineering\LAB\MI Calculations for Offspec Types\" _
    Range("C3") & "_" & Range("C5") & "_MI Calc", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
0
Steve LowryPrincipal ChemistAuthor Commented:
Martin, when I pasted the above for the code for my command button, I got a compile/syntax error.
0
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Saurabh Singh TeotiaCommented:
Small changes to what Martin posted..use this..

ActiveWorkbook.SaveAs Filename:= _
"\\lpofs01\groups\Engineering\LAB\MI Calculations for Offspec Types\" _
    Range("C3").Value  & "_" & Range("C5").value & "_MI Calc.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

Open in new window


If this still give you an error..can you take a screenshot of error message and paste here..
0
Martin LissOlder than dirtCommented:
There was a missing ampersand

ActiveWorkbook.SaveAs Filename:="\\lpofs01\groups\Engineering\LAB\MI Calculations for Offspec Types\" _
      & Range("C3") & "_" & Range("C5") & "_MI Calc", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
0

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
Saurabh Singh TeotiaCommented:
Lol@Martin It still missing that.. it will be..Friday...it's always been crazy...

ActiveWorkbook.SaveAs Filename:= _
"\\lpofs01\groups\Engineering\LAB\MI Calculations for Offspec Types\" _
   & Range("C3").Value  & "_" & Range("C5").value & "_MI Calc.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

Open in new window

0
Martin LissOlder than dirtCommented:
No, it's there.
0
Saurabh Singh TeotiaCommented:
Hahaha@You edited that one.. :-)
0
Steve LowryPrincipal ChemistAuthor Commented:
Thanks to both of you for your quick help.
0
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 Excel

From novice to tech pro — start learning today.