excel - Updating a workbook and Saving using VBA -


i've created macro should refresh data sources. it's data sources sql servers, , such automatically pull password box required. if you've input password server since excel last opened doesn't ask password.

i've managed following piece of code together, it's not behaving i'd expect

sub bsr_refresher() 'refreshes spreadsheet , copies today's date  'clears filters  on error resume next activeworkbook.showalldata   'refreshes spreadsheet    each objconnection in thisworkbook.connections     'get current background-refresh value     bbackground = objconnection.oledbconnection.backgroundquery      'temporarily disable background-refresh     objconnection.oledbconnection.backgroundquery = false      'refresh connection     objconnection.refresh      'set background-refresh value original value     objconnection.oledbconnection.backgroundquery = bbackground    next  'saves spreadsheet  activeworkbook.saveas filename:=activeworkbook.path & "\\company.local\anydrive\company\projects\project001\reporting\report updates" & format(date, ddmmyyyy) & ".xls"       end sub 

from knowledge of vba should following:

1) clear filters tables

2) run data refresh (cribbed here)

3) save \\company.local\anydrive\company\projects\project001\reporting\report updates (fake names, actual structure) file name filename 08/07/2015 (where filename current name of file)

any clues why is?

edit:

as per comments, not saving documents require.

==================

i've altered code , it's still not working. i've moved things around loop leading repeated deletion of 1 of sheets due addition of "delete sheet" step.

sub bsr_refresher() 'refreshes spreadsheet , copies today's date  ' gets name save new workbook   dim strsavename string     dim strfolderpath string     strsavename = "report" & format(date, ddmmyyyy) & ".xlsx"     strfolderpath = "\\company.local\anydrive\company\projects\project-001\reporting\status report updates\"     strsaveas = strfolderpath & strsavename 'deletes sheet1, clears filters  application.displayalerts = false      sheets("sheet1").select      activewindow.selectedsheets.delete  application.displayalerts = true  'refreshes spreadsheet on error resume next activeworkbook.showalldata     each objconnection in thisworkbook.connections         'get current background-refresh value         bbackground = objconnection.oledbconnection.backgroundquery          'temporarily disable background-refresh         objconnection.oledbconnection.backgroundquery = false          'refresh connection         objconnection.refresh          'set background-refresh value original value         objconnection.oledbconnection.backgroundquery = bbackground next  'saves spreadsheet   activeworkbook.saveas filename:=strsaveas   end sub 

my issue doesn't seem save needs :s

activeworkbook.path & "\\company.local 

double "\" sign problem. cut 1 of , should fine (or @ least you'll move other problem if turns out there 1 later).

also, calling project project-001 bite once have several projects , can't remember number doing what. best start giving proper descriptive names right @ start.


edit: don't specify file format in saveas - may cause problems. such code help?

sub testsave()      dim savepath string      savepath = thisworkbook.path & "\\testdir\" & "test.xlsm"      thisworkbook.saveas filename:=savepath, fileformat:=52  end sub 

51 xlsx, 52 xlsm, 56 xls


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -