<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I send a VB command to Word that calls a Macro that requires a v in Microsoft Integration with SAS</title>
    <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68210#M926</link>
    <description>Sorry I didn't read the WordBasic help document carefully. You need one more argument to print a range of pages. For example,&lt;BR /&gt;
put '[fileprint .range=4 .pages="2-2"]';&lt;BR /&gt;
&lt;BR /&gt;
Or, the sendkeys work-around is&lt;BR /&gt;
put '[sendkeys("^p")]'&lt;BR /&gt;
	'[sendkeys("%g")]'&lt;BR /&gt;
	'[sendkeys("2-2")]'&lt;BR /&gt;
	'[sendkeys("{enter}")]'&lt;BR /&gt;
	;&lt;BR /&gt;
&lt;BR /&gt;
Hope it helps.</description>
    <pubDate>Tue, 13 Jan 2009 16:06:43 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-01-13T16:06:43Z</dc:date>
    <item>
      <title>How do I send a VB command to Word that calls a Macro that requires a value</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68203#M919</link>
      <description>I have a SAS Macro that constructs VB commands to send to Word, but I'm stuck on trying to call a Word Macro that requires a value passed to it (such as: call prt_pgs_rng ("1-10"). I keep getting a Word Compile error.&lt;BR /&gt;
&lt;BR /&gt;
Any thoughts?</description>
      <pubDate>Wed, 07 Jan 2009 16:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68203#M919</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-07T16:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send a VB command to Word that calls a Macro that requires a value</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68204#M920</link>
      <description>more details please! are you invoking the Word Macro from SAS or within Word? If it's the former case, are you using DDE? listing the code would be helpful too.</description>
      <pubDate>Wed, 07 Jan 2009 20:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68204#M920</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-07T20:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send a VB command to Word that calls a Macro that requires a value</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68205#M921</link>
      <description>I'm using DDE to send VB commands to Word to print all or selected pages of the current Word Document. If I invoke a Word Macro that does not require any values passed to it, it works fine. But, if the Word Macro requires a value to be passed to it (such as the range of pages to be printed) it fails.&lt;BR /&gt;
&lt;BR /&gt;
These are the two Word Macros that I'm working with:&lt;BR /&gt;
&lt;BR /&gt;
Sub prt_pgs_all()&lt;BR /&gt;
' Print All Pages in Current Document&lt;BR /&gt;
    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _&lt;BR /&gt;
        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _&lt;BR /&gt;
        ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _&lt;BR /&gt;
        False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _&lt;BR /&gt;
        PrintZoomPaperHeight:=0&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Sub prt_pgs_rng(stPg As String)&lt;BR /&gt;
' Print a Range of Pages in Current Document&lt;BR /&gt;
' "1-1" = Print Page 1&lt;BR /&gt;
' "1-10" = Print First 10 pages&lt;BR /&gt;
    Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _&lt;BR /&gt;
        wdPrintDocumentContent, Copies:=1, Pages:=stPg, PageType:=wdPrintAllPages, _&lt;BR /&gt;
        ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _&lt;BR /&gt;
        False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _&lt;BR /&gt;
        PrintZoomPaperHeight:=0&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
To print all pages I send the following comand:&lt;BR /&gt;
put '[call prt_pgs_all]'; - this works fine&lt;BR /&gt;
To print only the first page I send the following command:&lt;BR /&gt;
put '[call prt_pgs_rng ("1-1")]'; - this does not work&lt;BR /&gt;
&lt;BR /&gt;
In Word I get a Compile error saying the Sub or Function is not Found and it displays the following code:&lt;BR /&gt;
&lt;BR /&gt;
Private Sub TmpDDE&lt;BR /&gt;
prt_pgs_rng__ ("1-1") &lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Note the underscores appended to the macro name - not sure where they came from, but when I remove them and continue the Subroutine works.&lt;BR /&gt;
&lt;BR /&gt;
If you can shed some light I'd appreciate it.</description>
      <pubDate>Thu, 08 Jan 2009 20:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68205#M921</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-08T20:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send a VB command to Word that calls a Macro that requires a v</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68206#M922</link>
      <description>according to &lt;A href="http://www2.sas.com/proceedings/sugi29/034-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/034-29.pdf&lt;/A&gt;, you may send via DDE only Word Commands or VBA subroutines without parameters.&lt;BR /&gt;
&lt;BR /&gt;
So as a work-around, you may just use the following put statement in SAS,&lt;BR /&gt;
put '[FilePrint .Pages="1-10"];&lt;BR /&gt;
&lt;BR /&gt;
Years have passed since that paper, there might be better techniques, but I don't know.</description>
      <pubDate>Sat, 10 Jan 2009 03:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68206#M922</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-10T03:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send a VB command to Word that calls a Macro that requires a v</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68207#M923</link>
      <description>Thanks for your response&lt;BR /&gt;
&lt;BR /&gt;
You answered one question - it seems you can't call a Word macro that passes parameters&lt;BR /&gt;
&lt;BR /&gt;
Your workaround makes sense and I could modify the statement within SAS to define the range of pages, but when I tried it as you described it it didn't work.&lt;BR /&gt;
&lt;BR /&gt;
Do you have any more suggestions?</description>
      <pubDate>Mon, 12 Jan 2009 21:15:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68207#M923</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-12T21:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send a VB command to Word that calls a Macro that requires a v</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68208#M924</link>
      <description>I don't know why it wouldn't work for you. I'm using Office 2003, and here's an example.&lt;BR /&gt;
/*&lt;BR /&gt;
options noxwait noxsync;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	call system('start winword');&lt;BR /&gt;
	rc = sleep(2);&lt;BR /&gt;
run;&lt;BR /&gt;
filename sas2word dde 'winword|system';&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	file sas2word;&lt;BR /&gt;
	put '[appactivate("Document1 - Microsoft Word")]';&lt;BR /&gt;
	put 'abcdefg';&lt;BR /&gt;
	put '[sendkeys("^a")]'&lt;BR /&gt;
		'[sendkeys("%o")]'&lt;BR /&gt;
		'[sendkeys("f")]'&lt;BR /&gt;
		'[sendkeys("Comic Sans MS")]'&lt;BR /&gt;
		'[sendkeys("{tab}")]'&lt;BR /&gt;
		'[sendkeys("bold")]'&lt;BR /&gt;
		'[sendkeys("{tab}")]'&lt;BR /&gt;
		'[sendkeys("20")]'&lt;BR /&gt;
		'[sendkeys("%k")]'&lt;BR /&gt;
		'[sendkeys("{enter}")]'&lt;BR /&gt;
		;&lt;BR /&gt;
	put '[fileprint .pages="1-1"]'; *there is a space between fileprint and .pages;&lt;BR /&gt;
	put '[filesaveas("n:\test.doc")]';&lt;BR /&gt;
	put '[filequit()]';&lt;BR /&gt;
run;&lt;BR /&gt;
*/&lt;BR /&gt;
I used only WordBasic functions. Because I don't want to look up very much the reference, I used SendKeys to send key strokes to Word. This function is capable of almost anything, but the key strokes need to be sent in proper order.&lt;BR /&gt;
For a complete list of WordBasic functions, please go to &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=1A24B2A7-31AE-4B7C-A377-45A8E2C70AB2&amp;amp;displaylang=en" target="_blank"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=1A24B2A7-31AE-4B7C-A377-45A8E2C70AB2&amp;amp;displaylang=en&lt;/A&gt;.</description>
      <pubDate>Mon, 12 Jan 2009 23:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68208#M924</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-12T23:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send a VB command to Word that calls a Macro that requires a v</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68209#M925</link>
      <description>Hi Urchin,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for sticking with me on this...&lt;BR /&gt;
&lt;BR /&gt;
I'm sorry I should have been more specific on how the command didn't work. My file printed, but it printed all the pages - not the range specified.&lt;BR /&gt;
&lt;BR /&gt;
I tried your code - changing it to read in a file that contained two pages and it still printed out the whole document instead of just the first page.&lt;BR /&gt;
&lt;BR /&gt;
options noxwait noxsync;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
call system('start winword');&lt;BR /&gt;
rc = sleep(2);&lt;BR /&gt;
run;&lt;BR /&gt;
filename sas2word dde 'winword|system';&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file sas2word;&lt;BR /&gt;
put '[fileopen .name = "n:\test.doc"]';&lt;BR /&gt;
put '[fileprint .pages="1-1"]'; *there is a space between fileprint and .pages;&lt;BR /&gt;
/*put '[filesaveas("n:\test.doc")]';*/&lt;BR /&gt;
put '[filequit()]';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
So the Print command works, but the pages parameter doesn't.</description>
      <pubDate>Tue, 13 Jan 2009 14:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68209#M925</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-13T14:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send a VB command to Word that calls a Macro that requires a v</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68210#M926</link>
      <description>Sorry I didn't read the WordBasic help document carefully. You need one more argument to print a range of pages. For example,&lt;BR /&gt;
put '[fileprint .range=4 .pages="2-2"]';&lt;BR /&gt;
&lt;BR /&gt;
Or, the sendkeys work-around is&lt;BR /&gt;
put '[sendkeys("^p")]'&lt;BR /&gt;
	'[sendkeys("%g")]'&lt;BR /&gt;
	'[sendkeys("2-2")]'&lt;BR /&gt;
	'[sendkeys("{enter}")]'&lt;BR /&gt;
	;&lt;BR /&gt;
&lt;BR /&gt;
Hope it helps.</description>
      <pubDate>Tue, 13 Jan 2009 16:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68210#M926</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-13T16:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send a VB command to Word that calls a Macro that requires a v</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68211#M927</link>
      <description>Thank you so much for your help.&lt;BR /&gt;
 &lt;BR /&gt;
The put statement worked with the .range parameter. The only question I have is what does that parameter define and should it always have a value of 4?</description>
      <pubDate>Wed, 14 Jan 2009 16:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68211#M927</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-14T16:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I send a VB command to Word that calls a Macro that requires a v</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68212#M928</link>
      <description>Nevermind - I was able to find some documentation that explained it. A .range value of 4 indicates you are going to use .pages to define the range. A .range value of 3 indicates you are going to use .from and .to to define the range.&lt;BR /&gt;
&lt;BR /&gt;
How cool is that! &lt;BR /&gt;
&lt;BR /&gt;
My SAS macro now reads in a .lst file, formats it (calling a pre-defined Word Macro), saves it as a .doc file and optionally, prints all or a range of pages.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again for your help!</description>
      <pubDate>Wed, 14 Jan 2009 16:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/How-do-I-send-a-VB-command-to-Word-that-calls-a-Macro-that/m-p/68212#M928</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-14T16:20:22Z</dc:date>
    </item>
  </channel>
</rss>

