开发者

MS Office Word 2007/2010 - how to view edit an existing built in mail merge SELECT?

开发者 https://www.devze.com 2023-02-09 10:38 出处:网络
I\'ve few word documents with Mail merge in them, I have to change the data source, but to do so I need to extract all the SELECT queries from these documents in order 开发者_如何学Pythonto detect the

I've few word documents with Mail merge in them, I have to change the data source, but to do so I need to extract all the SELECT queries from these documents in order 开发者_如何学Pythonto detect the tables and fields being used. (I don't have access to the old datasource as it doesn't exist anymore).

I've been searching the whole day, and can't figure out how to extract or show the SELECT query applied to each document. When I run one document a dialog box pops open saying Word is going to run the following query SELECT X,Y.... but as the queries are quite big I can't see their whole structure, I can't resize the dialog box neither...

Is there a way to extract these selects?


If you open the word .docx file with an unzip utility program like 7-Zip this will reveal the folder/file structure within.

The root folders should be something like docProps, Word, _Rel. Look in the Word folder and open the "settings.xml" file. within this you should see the query (together with the database column mappings to fields within the document).

I tried this in Word 2007 mapping to a customers table and the query saved was:

query w:val="SELECT * FROM "Customer" "

Edit: extract from settings.xml (I had to strip out the < and > to get this to show up)

w:settings xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word"
w:zoom w:percent="100"/
w:mailMerge
w:mainDocumentType w:val="formLetters"/
w:linkToQuery/
w:dataType w:val="native"/
w:connectString w:val="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=Chinook;Data Source=NEWDELL\SQLEXPRESS;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=NEWDELL;Use Encryption for Data=False;Tag with column collation when possible=False"/
w:query w:val="SELECT * FROM "Customer" "/
w:dataSource r:id="rId1"/
w:viewMergedData/
w:odso ....etc


Try pressing Alt + F11 in Word to open the VBA editor.

You should find at least one module, and I would imagine that whatever code it's executing will be within one of these.

If not, possibly a macro?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号