I'm using Vb.Net to automate an excel spreadsheet generation. I'm drawing a border around a range, but for some reason the text in the first columns hides the border. Is there some way of sending this text to "background", like a z-index in web, so that the border displays correctly?
This is the relevant line of code:
range = sheet.Range("B" + (sectionStart).ToString, "M" + (currentLine).ToString)
range.BorderAround(XlLineStyle.xlContinuous, XlBorderWeight.xlThin)
I would say your best bet is to wrap the text in column A, we get this problem a lot here at work and it usually solves the issue.
Try adding:
sheet.Range(“A:A″).IsWrapText = True
To your code, hope this helps!
Related
I have been able to change the background color of Word tables in the body of the document with: oSourceTable.Shading.BackgroundPatternColor = wdRed. However, the same code does not work for header or footer Word tables. I have also tried setting the Section back color as well, but to no avail. The code runs, but the Headers and Footers are always displayed with white backgrounds.
I have done mostly Excel VBA, and only a little bit of Word VBA so maybe I am missing something obvious here. Thanks in advance for any ideas and/or suggestions.
As requested, here is the code I am using. vTableBackColors is just an array of colors. This code is for the body tables and is working perfectly.
For Each oWordTable In oWordDoc.Tables
lIndex = lIndex + 1
oWordTable.Shading.BackgroundPatternColor = vTableBackColors(lIndex)
Next
I tried to do the same thing for the header and footer tables, but it does not work. I tried using the Header/Footer tables as below.
For Each oWordSection In oWordDoc.Sections
For Each oWordTable In oWordSection.Headers.Item(wdHeaderFooterPrimary).Range.Tables
' I selected this one to see if it would make a difference.
oWordTable.Select
oWordTable.Shading.BackgroundPatternColor = m_HeaderBackColor
Next
For Each oWordTable In oWordSection.Footers.Item(wdHeaderFooterPrimary).Range.Tables
oWordTable.Shading.BackgroundPatternColor = m_FooterBackColor
Next
Next
I also tried using the Section Headers / Footers directly. Before and after checking shows that the BackgroundPatternColor has changed as desired, but it is not displayed.
oWordSection.Headers.Item(wdHeaderFooterPrimary).Range.Shading.BackgroundPatternColor = m_HeaderBackColor
Here is a screenshot showing the colorized body tables and the unchanged header.
Is it possible that, unlike the Body table colors, the Header / Footer colors are never displayed as such by the Word designer, but are only true at runtime?
Thanks for any additional information.
«I have been able to change the background color of Word tables in the body of the document with: oSourceTable.Shading.BackgroundPatternColor = red.» That would not work unless you have defined 'red' as an RGB value.
As for the header/footer issue, this works for me:
For Each oWordSection In oWordDoc.Sections
For Each oWordTable In oWordSection.Headers.Item(wdHeaderFooterPrimary).Range.Tables
oWordTable.Shading.BackgroundPatternColorIndex = wdRed
Next
For Each oWordTable In oWordSection.Footers.Item(wdHeaderFooterPrimary).Range.Tables
oWordTable.Shading.BackgroundPatternColorIndex = wdRed
Next
Next
Perhaps your underlying problem is in the value you have assigned to 'm_HeaderBackColor' and 'm_FooterBackColor' - which your posted code doesn't show. It's also possible your code is addressing the wrong headers/footers (i.e. maybe it's not the primary ones you need to address).
I tried to insert the background image using following code:
Pic = "C://Picture/Logo1"
Activesheet.SetBackgroundPicture Pic
This inserts the picture to full sheet but I want to add it to particular cell or a range of cells. Please help
As far as I know excel doesn't support appending the image to a cell (with or without VBA).
The background of a single cell supports colors/gradients/fill-patters, but not the pictures.
It is possible however, to "place" the picture (shape) object with the same width and height right above the cell and make it locked and move around together with the cell if somebody attempts to resize cell widths. I personally wouldn't go that way, too much to code and too much risk of breaking the structure.
I'm new here, so I might have not seen a possibility to upload my problem files, which would make it easier to describe the problem.
Edit: The files a here: https://drive.google.com/file/d/0B--IbmtX58h8TnVrdlRyUXZ5a2dEOVJBQkplVjFuVEVMVXhJ/view?usp=docslist_api
and: https://drive.google.com/file/d/0B--IbmtX58h8TFR6d3FkWlZpSGFVUGF5bHVhRTR5ZTlnbXAw/view?usp=docslist_api
(Thank you for the idea, Steve)
What it is about:
I have two documents with different master templates reacting completely different on the same set of macros and I have no idea how and why this can happen and how to repair or avoid it.
Two of the macros just create objects - one is a single textbox, the other one a group of a rectangle and a textbox . The first mentioned appears on the position defined in the code in one of the templates, but a bit below it in the other one. Even more strange is the behavior of the group. The rectangle appears on the correct position in both of the templates, the textbox only in one of it.
Next is a macro for increasing the paragraphing between text lines by 3 pt. It works fine in one template, but in the other template it increases the spacing by 43.2 pt!
Macro number four is made to set back the paragraphing space after back to 0. This one works fine in both templates.
Funny enough, the mistakes appear in opposite to each other. The single textbox and the group produce their error in the template, where the spacing tool works fine, and the spacing tool does strange things in the template where the single textbox and the group work well.
Any idea will be appreciated!
Thanks,
RG
I work with PowerPoint 2010.
Your footnote is getting misplaced because the default text settings in one presentation are different from those in the other; in this case the auto fit setting.
' in this section of your FOOTNOTE routine:
With .TextFrame
' Add this next line and it will work as expected
.AutoSize = ppAutoSizeNone
.TextRange.Text = "Note: " & vbCrLf & "Source: "
.VerticalAnchor = msoAnchorBottom
Likewise, in your SectionMarker subroutine:
With .TextFrame
' add this
.AutoSize = ppAutoSizeNone
' then the rest of your code
Then it all works as you'd expect. Or at least, it works the same with both templates.
I have a sheet in my workbook, and i'm trying to make it look better.
I Tried a google search but no luck...
i know how to apply a picture to a whole sheet (but it gets mosaique) :
Sheets("Phase Psy").SetBackgroundPicture Filename:=ThisWorkbook.Path & "\images\magie\slayers\lina_inverse_vs__voldemort.jpg"
also for comments, you can use either a picture or some nice preset textures :
Range("A1").Comment.Shape.Fill.Userpicture "c:\myPic.JPG"
or
Range("A1").Comment.Shape.Fill.PresetTextured msoTexturePapyrus
I would like something similar but not applyed to comments but to a range.
Is there a way to add a picture or texture, or pattern (but not the ugly ones you can find with format cell>Fill>Pattern Style) ?
Thanks for any advice.
Sub Test2()
ActiveSheet.Pictures("Picture 1").Width = ActiveSheet.Range("A1").MergeArea.Width
ActiveSheet.Pictures("Picture 1").Height = ActiveSheet.Range("A1").MergeArea.Height
End Sub
The above will fill the Cell with the picture, keeping the aspect ratio, until either the full width or height of the cell is acheived
I am writting to an excel file from my vb code. The code goes as below
xlsheet3 = xlBook.Sheets.Add(After:=xlSheet)
With xlsheet3
.Columns(5).NumberFormat = "#"
.Cells(j + 1, 5) = someStringValue 'Here "j" is a row counter and this line is in a "for loop"
end with
After writing to excel, most of the cells in excel are correct. But some of the cell's text comes as ####### however if I click on the cell, formula bar shows the correct result. I have tried giving single code before adding the text still that did not help.
Please help me in resolving this.
Thank you
There is not any issue with your code. You need to increase the width of the column or have to use word wrap. In excel if your value is not fully visible it shows it is "######".
If widening and wrapping text doesn't work and the format is set to text which allows display of only 255 characters, try changing the format to general.
This just indicates that the cell is too small for showing the result: make it wider.
See https://superuser.com/questions/65556/excel-displays-for-long-text-whats-wrong for some common reasons why Excel displays "######" in cells.
Either the cell is too narrow to display the contents or the contents are over 256 characters.
Check what you're writing to the cell. If it's not too long then all you need to do is resize the column to fit the new contents.
This is simply what Excel does when the data in a column is too wide to be displayed in the current column width. Make the column slightly wider and you will see all your data.
To autosize the column so it is wide enough to display all its data, double click the column divider at the right edge of the column, in the header bar.