Getting a carriage return or something before a pic in a table cell so that I can show the border??

Hi All

Some of you have kindly assisted me in getting 'x' number of pictures into 
'x' number of table cells in a Word document using VBA, but I seem to have 
hit a brick wall when it comes to getting the top border line to appear on 
my inserted pics.

Now as soon as I manually add a carriage return above the pictures my top 
border appears perfectly, but my code won't let me add this carriage return 
before the pic.  When the pic gets inserted it automatically obliterates 
anything that was already in the cell and I get a pic with no top border.

I've tried giving a top margin to each cell so that it forces the issue, but 
it doesn't work.  It looks like Word needs that carriage return prior to 
inserting the pic.

My code is currently as follows:

  For y = 0 To UBound(arrData, 2)
   If Len(arrData(2, y)) > 0 Then ' check that a picture name exists
    Set oPic = 
oNewDoc.Tables(intTable).Rows.Add.Cells(2).Range.InlineShapes.AddPicture(arrData(2, 
y), False, True)
    With oPic
     .Width = 200
     .Height = 150
     .Borders.OutsideLineStyle = wdLineStyleSingle
     .Borders.OutsideLineWidth = wdLineWidth075pt
     .Borders.OutsideColor = wdColorAutomatic
    End With
   End If

   strText = arrData(1, y) & vbCrLf  ' desc
   If Len(arrData(3, y)) > 0 Then strText = strText & arrData(3, y) & vbCrLf 
' comment
   oNewDoc.Tables(intTable).Rows.Add.Cells(2).Range.Text = strText
  Next

The above works fine I just need to get a carriage return (or anything!!!) 
that gets my top border to appear.  I've got the left, right and bottom 
borders no problem :0)

Any ideas? 


0
Mojo
4/6/2010 9:00:17 PM
word.vba.general 1023 articles. 1 followers. Follow

1 Replies
851 Views

Similar Articles

[PageSpeed] 24

The simplest solution is to add some Space Before (maybe 6 pt) to the
paragraphs in the table. If the table is predefined in a template used
to create oNewDoc, you can just add the space to the table's text in
the template. If the table is built by code in your macro, then you
can use a line like this:

  oNewDoc.Tables(intTable).Range.Paragraphs.SpaceBefore = 6

It might be a good idea to add some Space After as well.

If you really want a paragraph before the picture (strongly NOT
recommended), the problem with what you're doing now is this: The
range you're using to insert the picture is Cells(2).Range, and that
includes the paragraph mark you already put in the cell. The
AddPicture replaces the whole range with the picture. The solution for
that is to declare a Range object, set it to Cells(2).Range, collapse
it to its start, and move one character to the right. Use that as the
range (a single point) to insert the picture:

Dim oRg As Range

....

   Set oRg = oNewDoc.Tables(intTable).Rows.Add.Cells(2).Range
   oRg.Collapse wdCollapseStart
   oRg.Move wdCharacter, 1
   Set oPic = oRg.InlineShapes.AddPicture(arrData(2, y), False, True)
   
--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.


On Tue, 6 Apr 2010 22:00:17 +0100, "Mojo" <please@dont.spam.com>
wrote:

>Hi All
>
>Some of you have kindly assisted me in getting 'x' number of pictures into 
>'x' number of table cells in a Word document using VBA, but I seem to have 
>hit a brick wall when it comes to getting the top border line to appear on 
>my inserted pics.
>
>Now as soon as I manually add a carriage return above the pictures my top 
>border appears perfectly, but my code won't let me add this carriage return 
>before the pic.  When the pic gets inserted it automatically obliterates 
>anything that was already in the cell and I get a pic with no top border.
>
>I've tried giving a top margin to each cell so that it forces the issue, but 
>it doesn't work.  It looks like Word needs that carriage return prior to 
>inserting the pic.
>
>My code is currently as follows:
>
>  For y = 0 To UBound(arrData, 2)
>   If Len(arrData(2, y)) > 0 Then ' check that a picture name exists
>    Set oPic = 
>oNewDoc.Tables(intTable).Rows.Add.Cells(2).Range.InlineShapes.AddPicture(arrData(2, 
>y), False, True)
>    With oPic
>     .Width = 200
>     .Height = 150
>     .Borders.OutsideLineStyle = wdLineStyleSingle
>     .Borders.OutsideLineWidth = wdLineWidth075pt
>     .Borders.OutsideColor = wdColorAutomatic
>    End With
>   End If
>
>   strText = arrData(1, y) & vbCrLf  ' desc
>   If Len(arrData(3, y)) > 0 Then strText = strText & arrData(3, y) & vbCrLf 
>' comment
>   oNewDoc.Tables(intTable).Rows.Add.Cells(2).Range.Text = strText
>  Next
>
>The above works fine I just need to get a carriage return (or anything!!!) 
>that gets my top border to appear.  I've got the left, right and bottom 
>borders no problem :0)
>
>Any ideas? 
>
0
Jay
4/7/2010 12:55:45 AM
Reply:

Similar Artilces:

Changing Cells and entering data in them
Thanks for the help again. Big thanks to Steve you've got me this far. I went out and bought a book, but it's like reading a foreign language. I was informed today that I can't have message boxes come up. I need to have the code point at the cells and if they are blank turn which ever one is blank red or if both are then both turn red then pause for each cell to be filled in. Cell F14 "Last Name" then automatically go to Cell F16 "First Name" on tab or enter. Basically if Cell F22 or F23 has an X in it, Cells F14 an F16 turn red and cell F14 has the focus...

POST or GET?
(apologies if this is OT but I couldn't find an HTTP newsgroup) I am writing an MFC client application which speaks to an HTTP server. The server will send text data to the client, the client will modify and return that data to the server along with a small amount of new data. Should I use GET or POST to get the data from the server? "Richard" <richard@hello.com> wrote in message news:zWudf.14758$Cq4.8824@newsfe7-gui.ntli.net... > I am writing an MFC client application which speaks to an HTTP server. The > server will send text data to the client, the client...

"View Image Slide Show"
(Running Vista Ultimate 64-bit, SP-2, IE-8, WM-6, WLM-09, classic mode, dial-up.) In Windows Live Mail, most of the time when I receive an email with 2 or more .jpg files attached, there is an option shown as: "View Image Slide Show". Clicking on that line brings up a screen which allows me to cycle through the attached .jpg files, viewing them in sequence, going back and forth as I desire. About every 10 or so emails having some .jpg files as attachments I receive one, with several such attachments, which does NOT have the "View Image Slide Show" op...

Pivot Table Question #5
How do I make the row headers show up in front of each row on pivot table instead of just once on the first row of a section? Thanks Try this: Copy the pivot table Do a Paste Special > Values into another sheet Ensure that the top left cell is A1 Run the Sub FillBlanks() below (from MVP Debra D) Sub FillBlanks() 'by Debra Dalgleish 7-Dec-2001 'fill blanks cells with data from above Range("A1").CurrentRegion _ .SpecialCells(xlCellTypeBlanks) _ .FormulaR1C1 = "=R[-1]C" Range("A1").CurrentRegion.Copy Range("A1").PasteS...

Cannot open Outlook, keep getting Send error report of Microsoft.
We are having problems with Outlook 2003. Everytime we try to open, we get this: Send error report to Microsoft. Any ideas why? All windows and office update have been completed. ...

Savings a/c cashflow doesn't show withdrawals
Money 2003 When I do a cashflow forecast for my savings a/c it doesn't take into account transfers to my "cash" account - the one I use to keep track of what I spend my cash on. Consequently when I do the cashflow it gives an unreal projection of savings. I wish I could save $3000 in 2 months but it's not going to happen... ...

Is anyone an expert with outlook that I can call on the phone?
How do I share calenders between outlook and my MSN Premier account? Assuming you are using the outlook connector, you need to set the msn account to be the default message store then outlook will use the msn calendar as the default. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com Outlook Tips by email: mailto:dailytips-subscribe-request@lists.outlooktips.net EMO - a weekly newsletter about Outlook and Exchange: mailto:EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH.EASE.LSOFT.COM You can access this...

Show date, time & day of week in one cell
Can I show the date, time and day of week in one cell. I have: 09/03/07 8:30 AM in one cell using the format (Format/Cells/Custom): [$-409]mm/dd/yy h:mm AM/PM;@ Excel refuses to accept ddd for Mon or dddd Monday at the end of the format I want it to read: 09/03/07 8:30 AM Monday in 1 cell. I have Excel 2003. One way: mm/dd/yy h:mm AM/PM dddd;@ In article <Xns99B8A3CAF9130pencilunlistedcom@208.49.82.220>, Burp <burp@beep.comINVALID> wrote: > Can I show the date, time and day of week in one cell. > > I have: > 09/03/07 8:30 AM > in one cell using the for...

get a result of an sql into a field
Hi there I would like to get a result of an sql execution (ms sql server) into aq filed. example i A1 I have a ID number in A2 I would like to get the result of something like this 'select name from address where id=A1' Does this exist in Excel ? Thanks in advance Ralf Here is the sub i have written for loading an Sql Query into th worksheet. Parameters: Server Name DataBase Name SQL Command Target Sheet name Column to begin from Row to begin from ex: CALL LoadData("MyServer","MyDataBase","Select UserName fro TblNames", "QueryData"...

default values in a cell
Hello, can you help me please Cell B1 contains a complex mathematical formula which requires (in several places) a number from cell A1. Cell A1 can contain any integer number, but it is usually the same (30). I would like to be able to leave cell A1 empty, and only enter a number when it is not 30 , ie the default value of A1 is 30, unless specified. How do I go about this ? Should I look at conditional formatting, or put lots of IF functions into an already complex formula? Thank as always KK Use 2 cells Modify the complex formula to use B1 rather than A1 ( or any other un-u...

Can't do adjustment in analytical accounting
I am trying to change an analytical assignmnet through the Edit Analysis. When I try and change it, I receive an error stating "The Code of this Transaction Dimension cannot be adjusted". Has anyone seen this before? I have done similar changes many times, but I don't know why I can't now. Any insight would be helpful. Thanks, KJ Hi KJ What version of Gp are you running? I haveseen this happen in 8 but one of the service packs fixed it. (I think it was SP 4 or 5) Fliehigh "KJ" wrote: > I am trying to change an analytical assignmnet through the Edit >...

How do you invoke the Let and Get class Functions
I have create classes with the Let and Get functions and now I would like to use these functions to store and retrieve data in the class which will then be put into a collection. Here is the class functions: Private pBusPart As Double Private pStartTime As Date Private pIndex As Integer '''''''''''''''''''''' ' BusPart property '''''''''''''''''''''' Public Property Get BusPart() As Double BusPar...

Can I share entities in migration process?
The entities in CRM have only one owning user. If I want=20 who a user see a entity of another user, the entity must=20 be shared with this user.=20 Well, I want migrate entities who must be shared with some=20 users. Exists a way to do it? Thank you for pay attention and sorry my bad english. []'s Vin=EDcius Pitta Lima de Ara=FAjo ...

How to get to email from Word
Sorry to break the thread, but replying to the original thread now produces an error message :( The suggested changes don't make any difference to the essential premise that it all works as long as Outlook is running in the background. Stepping though the code has provided inconsistent results. It usually crashes at the line strEMail = Application.GetAddress("", strEMail, False, 1, , , True, True) when the address is selected from the dialog and you OK out of the dialog; but I have noticed that this call has produced crashes in other routines where Outlook is not running. Th...

I cannot get Outlook to send/receive. Error says object not found
I just installed Outlook2007. I cannot get the send/receive to work. That is when the error says Object not found. If I go to accounts and properties, I run the two tests and they complete fine. What should I try next? Outlook 2007 is the only new program, all the rest are from Office 2003 IMK <IMK@discussions.microsoft.com> wrote: > I just installed Outlook2007. I cannot get the send/receive to work. > That is when the error says Object not found. If I go to accounts and > properties, I run the two tests and they complete fine. What should I > try next? Outlook 2007 is ...

form fields not saving to table
I have created a database with a form and three of the fields are not saving the information to the table. I have checked the row and control sources and now at a loss and thoughts? As you scroll through existing records is the data of the table displayed? Post the SQL of the query or form source. -- Build a little, test a little. "Kim" wrote: > I have created a database with a form and three of the fields are not saving > the information to the table. I have checked the row and control sources and > now at a loss and thoughts? > > ...

is PHStat available and if so how do I get to it
I need help asap Tamika - > I need help asap < PHStat is Prentice Hall's statistical add-in for Excel. It's usually on the CD that's included with the textbook. For more info, try www.prenhall.com/phstat - Mike www.mikemiddleton.com ...

Table of Contents for each section
I have tried several times to create a TOC for each section of my document. They way it is now I can simply go to the Insert a TOC and it will insert e perfect TOC. All my text has been changed to the appropriate Level and I have no problem there. But I need to seperate the chapters to the start of their respective sections (I have next page breaks inserted at the start of every chapter). I have tried the bookmark method, no luck. I have tried other methods but I think my problem is that I have selected the appropriate fields and changed their levels appropriately. I have not mes...

Call & Place Graphic Based on Cell Value?
Is there any way to call & place a graphic image based upon a cell value? Maybe you can look at J.E. McGimpsey's page: http://www.mcgimpsey.com/excel/lookuppics.html documike wrote: > > Is there any way to call & place a graphic image based upon a cell value? -- Dave Peterson ...

Status in table PurchaseOrderEntryDetail
Hello, We're trying to populate serial # into the PurchaseOrderEntryDetail table and run across the column 'Status'. What are the possible values for Status column in this table? Most of the time we see status of '2'. What does that mean? Please help. Many Thanks & Best Regards, Nikki ...

How do I get Excell to sort dates that range from 1800 to 1900's
I have posted a cemetery survey on Excell spreadsheet. When I try to sort the birth dates or death dates in ascending or descending order the range of 1900 dates will sort but the 1800 dates fall after the 1900 and will not sort. Why? Is this inherit with this program? The WinXL default dates start with 31 December 1899, so earlier "dates" are interpreted as Text. You can use helper columns and text functions (LEFT(),RIGHT(),MID()) to put the Year, Month and Day in separate columns, then sort. Take a look here for additional workarounds: http://j-walk.com/ss/excel/files...

Is there a way to cut off unused cells on a sheet
It seems there are an infinite number of cells on a sheet. As I really dont have much info to enter on each sheet I was hoping there was a way I could somehow cut off all the extra stuff to the sides and bottoms. It is a hassle because everytime I scroll, it will scroll off the side or bottom way past what I was looking for. Thanks! A manual way is to goto the last used row and delete all rows below. Do the same with columns. SAVE -- Don Guillett SalesAid Software donaldb@281.com "newbie" <newbie@discussions.microsoft.com> wrote in message news:469AABE7-8D17-4B72-91C1-...

Automatically copy input from one cell to another
After I enter a value in one cell, how can I have it automatically enter it into another cell, within the same worksheet, or into a different worksheet. Thanks, Tom picktr@wowway.co -- Message posted from http://www.ExcelForum.com If you enter the value in A1 of sheet1, put this in the other cell in sheet1: =A1 or in another worksheet: =Sheet1!A1 In article <picktr.15c6uy@excelforum-nospam.com>, picktr <<picktr.15c6uy@excelforum-nospam.com>> wrote: > After I enter a value in one cell, how can > I have it automatically enter it into another cell...

Formating text in cells
Hello, does anyone know how to force Excel to keep the hyphen or dash character (-) with the associated numbers when putting multiple dash-#s in a cell and turning "wrap" formating on? This is the same problem I have in Word; when I add dash-#s (ie; -xxx, -yyy, -zzz) Office apps interpret dashes ( - ) as a hypehen to a word and will keep the dash/hyphen on the line above until there are enough characters to force the dash/hyphen to the next line. In my work we use the format; -xxx, -yyy, -zzz to denote multiple versions of the same base part. Work instructions to operators...

Unjoin tables in query
Hi, I have 2 tables (table1 & table2) in query that don't have a relational field each other. Table1 has Date, decription & amount. Table2 has RecordNo & filenm. I'd like to pull all fields in Table1 and only the last record of field Filenm in table2. How can I make a query to produce report like that. If anybody can tell me, I'm very appreciated. Thanks KT -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200707/1 It works. Thank you very much.... Jerry Whittle wrote: >First create a query called qryLastFil...