troubleshooting Question

Word Automation

Avatar of Aanvik
Aanvik asked on
Microsoft OfficeC#Microsoft Word
2 Comments1 Solution574 ViewsLast Modified:
I am looking for a VBA or C# code for word automation, where I can place the images on a word document. So far this is the code I have and it places the images not in order as shown in the attached screen.

Can anyone help?
            Object oMissing = System.Reflection.Missing.Value;
            Object oTrue = true;
            Object oFalse = false;

            word.Application oWord = new word.Application();
            word.Document oDocument = new word.Document();

            oWord.Visible = true;
            oDocument = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            string[] dirs = Directory.GetFiles(txtFrom.Text, "FRONT*.jpg");
            foreach (string dir in dirs)
            {
 
                var shape = oWord.Selection.InlineShapes.AddPicture(dir, ref oMissing, ref oTrue, ref oMissing);
                shape.Width = 250;
                shape.Height = 150;

            }

            //Back folder Now..


            oWord = new word.Application();
            oDocument = new word.Document();

            oWord.Visible = true;
            oDocument = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            dirs = Directory.GetFiles(txtFrom.Text, "BACK*.jpg");
            foreach (string dir in dirs)
            {

                var shape = oWord.Selection.InlineShapes.AddPicture(dir, ref oMissing, ref oTrue, ref oMissing);
                shape.Width = 250;
                shape.Height = 150;

            }
BACKS.doc
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros