VBA Dynamic Save As, Microsoft Project to Excel -


i trying create macro export microsoft project file excel file. through use of macro recording have got line of code accomplishes using export wizard, want file path , file name dynamic can use macro on different projects. have been searching many other threads , microsoft website no luck. possible?

here have:

   sub formatandsave ()     filesaveas name:="c:\users\xxxxxx\sharepoint\projects\projecttype\hxh\myproject.xlsx",_               formatid:="msproject.ace", map:="mymap"     end sub 

one idea tried was:

   active.workbook.saveas filename:=title 

any appreciated!

for sake of simplicity, let's assume answers below project located @ c:\projects\myproj.mpp

i think you're after string replace function. like:

dim excelfilepath string excelfilepath = replace(activeproject.fullname, ".mpp", ".xlsx") debug.print excelfilepath 'the output c:\projects\myproj.xlsx 

if you're unfamiliar string manipulation in vb/vba, search web "vba string manipulation". microsoft has decent article here: https://msdn.microsoft.com/en-us/library/aa903372(v=vs.71).aspx

a few other things may handy these variables:

activeproject.fullname 'shows full path & name, you'd "c:\projects\myproj.mpp" activeproject.path     'shows path, you'd "c:\projects\" activeproject.name     'shows file name, you'd "myproj.mpp" 

finally, 1 caveat i've seen activeproject.fullname , activeproject.name variables may or may not provide file extension depending on local windows environment settings. i've observed if windows explorer configured hide file extensions, these variables withhold extension; if explorer configured show them, provided in variables. make sure code robust both cases, or make sure have control on environment code run.


Comments

Popular posts from this blog

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

html - How to custom Bootstrap grid height? -