views:

161

answers:

1

I want to position an image on the page the user is looking at, however I cannot find how to get the currently visible page/scroll in pixels.

Anybody know which object and property could give me that?

A: 

Are you trying to control Word from outside Word or is it an integrated control?

I think you want: Object oMissed = doc.Paragraphs[1].Range;

This code below is for an InlineShape, not Shape object. Shape object is for text-wrapping.

Code:

using System;    
using System.Collections.Generic;    
using System.ComponentModel;    
using System.Data;    
using System.Drawing;    
using System.Linq;    
using System.Text;    
using System.Windows.Forms;    
using Word = Microsoft.Office.Interop.Word;


namespace WordAddIn3
{

   public partial class Form1 : Form
   {

      public Form1()
      {

           InitializeComponent();

      }

      private void button1_Click(object sender, EventArgs e)
      {

          Word.Application wdApp = Globals.ThisAddIn.Application;
          Word.Document doc = wdApp.ActiveDocument;

          string fileName = "c:\\testimage.jpg"; //the picture file to be inserted

          Object oMissed = doc.Paragraphs[1].Range; //the position you want to insert
          Object oLinkToFile = false; //default
          Object oSaveWithDocument = true;//default   

      doc.InlineShapes.AddPicture(fileName, ref oLinkToFile, ref oSaveWithDocument, ref oMissed);
      }

   }



}

Microsoft: HOWTO: How To Get 32-bit Scroll Position During Scroll Messages

Similarly, you may want to look at this SO question on How do I get the scroll position from Microsoft Execl -- which I just realized was asked by you..

0A0D
The During scroll will not help me I am afraid. The user might have scrolled before my application comes into play. I was hoping that the Execl answer would lead to the Word answer but the API seems just different enough.
Phil Hannent
Gotcha. See my edited message.
0A0D