I'm trying to automate an export of shape data to an Access database. I can use the run method of addon("export to database") for each of the several pages I have in my document.
But then I don't know how to pass parameters so that the table name is set by the code and the user doesn't have to click "OK" for each of the pages.
I have been searching high and low and I can't find any reference for what the syntax needs to be and what I've tried isn't working.
Here is my code currently
Dim doc As Visio.Document
Dim Pages As Visio.Pages
Dim Page As Visio.Page
Dim Adn As Addon
Dim PageName As String
Dim strCommand As String
Set doc = Application.ActiveDocument
Set Pages = doc.Pages
Set Adn = Visio.Application.Addons("Export to Database...")
For Each Page In Pages
PageName = Page.Name
strCommand = "/table=PageName"
Adn.Run ("/S-RUN" & strCommand)
'Application.AlertResponse = 1
Next
Could somebody please help me in getting the syntax correct?
Thank you.
Okay, I got most of it to work. Now I'm trying to get it to just hit OK for each of the dialog boxes that pop up in the Export to Database event. I used AlertResponse = 1. That got the popups to go away but it doesn't seem to be actually clicking on OK. The code runs but nothing exports.
Is there something other than AlertResponse that should be used with regard to the Export to Database addon? Or is there some other setting I need to use?
Here is my code
Dim myDoc As Visio.Document
Dim myPages As Visio.Pages
Dim myPage As Visio.Page
Dim myAddon As Addon
Dim myCell As Visio.Cell
Dim BookTitle As String
Dim PageName As String
Dim TableName As String
Set myDoc = Application.ActiveDocument
Set myPages = myDoc.Pages
Set myAddon = Visio.Application.Addons("Export to Database...")
BookTitle = myPages("Print Production").Shapes("Title").Text
'set alert response to automatically choose "OK" on modal popups
Application.AlertResponse = 1
'loop through all pages
For Each myPage In myPages
PageName = myPage.Name
TableName = BookTitle & "_" & PageName
Application.ActiveWindow.Page = myPages.Item(PageName) 'page must be active page to set User.ODBCExportTable cell
Set myCell = myDoc.Pages.Item(PageName).PageSheet.Cells("User.ODBCExportTable")
myCell.Formula = """" & TableName & """"
myAddon.Run ("")
Next
'reset application alert response
Application.AlertResponse = 0
Okay, I found that there is another command called "Re-export" which is not in the list of add-ons run from the tool bar. But this effectively reruns the last export exactly and does not give any prompts. So by changing the add-on that's run to re-export then I could get rid of the AlertResponse and get a fully automated export of all pages, with no user prompts.
Here is my code.
Dim myDoc As Visio.Document
Dim myPages As Visio.Pages
Dim myPage As Visio.Page
Dim myAddon As Addon
Dim myCell As Visio.Cell
Dim BookTitle As String
Dim PageName As String
Dim TableName As String
Set myDoc = Application.ActiveDocument
Set myPages = myDoc.Pages
Set myAddon = Visio.Application.Addons("DBREX")
BookTitle = myPages("Print Production").Shapes("Title").Text
'loop through all pages
For Each myPage In myPages
PageName = myPage.Name
TableName = BookTitle & "_" & PageName
Application.ActiveWindow.Page = myPages.Item(PageName) 'page must be active page to set User.ODBCExportTable cell
Set myCell = myDoc.Pages.Item(PageName).PageSheet.Cells("User.ODBCExportTable")
myCell.Formula = """" & TableName & """"
myAddon.Run ("")
Next
Now the code runs through each page, resets the table name and exports to an Access database
Browser ID: smf
(is_webkit)
Templates: 1:
Printpage (default).
Sub templates: 4:
init,
print_above,
main,
print_below.
Language files: 1:
index+Modifications.english (default).
Style sheets: 0:
.
Hooks called: 51 (
showintegrate_autoload, cache_get_data, integrate_pre_load, integrate_load_session, integrate_verify_user, cache_get_data, integrate_user_info, integrate_load_board, cache_get_data, integrate_board_info, cache_get_data, integrate_allowed_to_general, integrate_allowed_to_general, integrate_boards_allowed_to, integrate_mod_cache, integrate_allowed_to_general, integrate_pre_load_theme, cache_get_data, integrate_allowed_to_general, integrate_simple_actions, integrate_allowed_to_general, integrate_load_theme, integrate_pre_log_stats, cache_get_data, integrate_actions, integrate_pre_parsebbc, integrate_bbc_codes, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_menu_buttons, integrate_current_action, integrate_theme_context, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general)
Files included: 25 - 925KB. (
show/home/iw0lkfe3x6cq/public_html/vgforum/index.php, /home/iw0lkfe3x6cq/public_html/vgforum/Settings.php, /home/iw0lkfe3x6cq/public_html/vgforum/cache/db_last_error.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/QueryString.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Auth.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Errors.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Load.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Security.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Compat.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Db-mysql.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/CacheApi.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/CacheApiInterface.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/APIs/FileBased.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Charset.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/Metadata.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/QuickCheck.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Session.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Logging.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Class-BrowserDetect.php, (Current Theme)/languages/index.english.php, (Current Theme)/languages/Modifications.english.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Printpage.php, (Current Theme)/Printpage.template.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/CaseUpper.php)
Memory used: 748KB.
Tokens:
post-login.
Cache hits: 8: 0.00158s for 22,302 bytes (
showget modSettings: 0.00062s - 19983 bytes, get known_languages: 0.00024s - 1277 bytes, get board_parents-0: 0.00016s - 2 bytes, get permissions:-1: 0.00014s - 50 bytes, get theme_settings-1: 0.00012s - 980 bytes, get hostlookup-216.73.216.125: 0.00001s - 0 bytes, get log_online-update: 0.00025s - 10 bytes, get menu_buttons--1-english: 0.00004s - 0 bytes)
Cache misses: 2: (
showget hostlookup-216.73.216.125, get menu_buttons--1-english)
Queries used: 11.
[Show Queries]