How do I open the Header/Footer in a Word programatically from MATLAB?

13 ビュー (過去 30 日間)
Joe
Joe 2011 年 2 月 7 日
編集済み: Walter Roberson 2024 年 10 月 14 日
I have code to open up a word document and edit the body of the document; however I don't know how to open/edit the header/footer. Does anyone know how to do this?
  2 件のコメント
Jan
Jan 2011 年 2 月 7 日
Does this question have any connection to Matlab? If so, please explain any details.
Joe
Joe 2011 年 2 月 7 日
Yes it does, currently have an M-File which opens up a word document to edit the body of the active document; however, I am unsure as to how I can access the header/footer. Fangjun Jiang's answer below is getting me on the right track, but I am unsure as to how I need to define the Header/Footer(Index)

サインインしてコメントする。

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 2 月 7 日
I assume you want to access the header/footer in a Word document through Matlab m-script.
You can find these info in the Word help document, Microsoft Word Visual Basic Reference.
Here is the text regarding the Herder/Footer object:
Using the HeaderFooter Object Use Headers(index) or Footers(index), where index is one of the WdHeaderFooterIndex constants (wdHeaderFooterEvenPages, wdHeaderFooterFirstPage, or wdHeaderFooterPrimary), to return a single HeaderFooter object. The following example changes the text of both the primary header and the primary footer in the first section of the active document.
With ActiveDocument.Sections(1) .Headers(wdHeaderFooterPrimary).Range.Text = "Header text" .Footers(wdHeaderFooterPrimary).Range.Text = "Footer text" End With
  7 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 2 月 8 日
Try this:
R1=hSections.Headers.Item(1).Range;
get(R1)
I see there is a property called "Cells".
The point is that you probably need to drill down the structure of objects and properties of the Word application and find the right object and property to modify.
sitaramireddy Lankireddy
sitaramireddy Lankireddy 2019 年 3 月 15 日
How to extract header and footer for scanned documents? Any idea? please suggest.

サインインしてコメントする。

その他の回答 (1 件)

Philipp
Philipp 2024 年 10 月 14 日
I am trying to use this code, but there are some issues.
I have an existing word template which I want to reuse. It has already an header inside it.
When coding hSections=hDoc.Sections.Add; I get an unwanted new section into my word file.
Without it Headers is an unrecognized funciton or variable.
Maybe you can help on how to get access to an existing header without changing the rest of the word file?

カテゴリ

Help Center および File ExchangeActiveX についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by