How to check for particular text irrespective of the font of the text in excel VBA - vba

I am writing a code piece as:
If Sheets("Data").Cells(27, 3).Value = "Date" Then
Even after having "Date" in particular Cell this If loop doesn't works. After lot of digging I found that Excel in which I am searching is using some pre-defined font. If I delete the text "Date" already printed in the report and put my text as "Date", same code piece works perfectly. Please suggest way to make this codepiece work.

Related

Preventing excel from altering cell contents to take literal values

I have scripted out a module that reads data I paste in from a SQL dump, and converts it into a data insert script to SQL. It is working great, only problem is for cells that contain items like:
11-20
instead of filling my value as '11-20', it is converting it to '20-Nov'.
I have adjusted how i read the cell from text to value to value2, Text comes the closest to right (rest do a math calc that tosses my overall sheet off even worse, namely dates). I have also tried such things as a Range("X:X").clear and clearformat as well. This also does not do the trick.
How do I force my string read of this cell to be the literal CSV content, and ignore the formula/calculations that excel is tossing at me?
EDIT:
Thanks to BraX for the solution!
I was unable to accomplish this by copying from one tab to the next within Excel, but i did get it to work by pausing my operation with a message box prompting the user to simply navigate to SQL and put the contents of the data in to the clip board. This works perfectly now!
Cells.Select
Selection.NumberFormat = "#"
MsgBox "Please navigate to SQL and copy your data to be insurted, including headers. When done click OK"
Range("A1").Select
ActiveSheet.Paste
Before adding the data to the sheet, set the NumberFormat to # for the affected columns.
Example:
ActiveWorkBook.WorkSheets("Sheet1").Range("A:A").NumberFormat = "#"
That will format the values to Text and prevent them from being interpreted as a Date when the data is added. Once Excel decides it's a date, it's too late.
i am pretty sure all it takes is to format the cells, right click on the range of cells you want formatted as plain text, click "FORMAT CELLS" and under the "NUMBER TAB" it shows the "CATEGORY" of the type of formatting, e.g: "General, Number, Currency, etc" select where it says "Text" and click ok, any text will be evaluated the same way you write it, so even if you write "11-5-18" it will be just that and won't be considered a date or anything.

VBA Macro for MS Word to Ignore Spelling Errors in Selected Block of Text

VBA Noob here. I take my python programming notes in a word document since I can import images into it and align/format text quickly. Any code pasted into this document comes up as a spelling error. I'm trying to find a way to ignore spelling errors within a selected text area so I don't have to deal with ignoring each spelling error line of code individually. I don't want to turn off spell check in the document.
Ideally, I'd able to write a macro that read:
Selection.ShowSpellingErrors = True
but ShowSpellingErrors() can only be used with ActiveDocument. I was able to a record a macro that ignored spelling errors with:
Selection.LanguageID = wdEnglishUS
Selection.NoProofing = True
However, any new text I type into this also doesn't get proofed, which is something I don't want. I want to be able to write new text and see any errors I make. Thanks for any help!
Not a VBA Macro, but I think this answer may be relevant to your problem anyway.
Try creating a style for code which does not include spell check. Anything with this style does not get spell checked, while the rest of the document does. Sometimes I find the code shows the red underline, but if you run spell check it should just disappear without needing to be 'fixed'.
Create a new style, in the modify formatting dialog, go to Format > Language:
Tick the 'Do not check spelling or grammar' checkbox:
Highlight your code and use the new style. Any text not in this style will still be spellchecked:

VBA for changing font and colour of a cell if a certain word is typed in it

I have a somewhat large spreadsheet with a type of summary page that follows a calender layout.
On this page I manually change the font and color of cells to make it easy for me to find certain things on it. For example, (I lecture mathematics) if I have revision on a certain lesson, I make that cell bold and green. (exact type of green I can sort out myself). I want a VBA code if possible so that if I type the word revision into a cell on that sheet only, not whole workbook, that it would automatically change it to green.
Realistically, I don't manually type in the word revision always. Some of it uses lookups of various types to find what happens on that day to display a word (for example revision) in that given cell.
I don't know if this is possible to do. I realize that if "revision" is shown due to a lookup then the contents of that cell is not equal to "revision" but a formula which simply displays "revision"
Any assistance would be appreciated. If I have a basic code I can manipulate to get it right.
Thanks
Maybe you're looking for something along the lines of:
Sub CheckRevision()
Dim CurCell As Object
For Each CurCell In ActiveWorkbook.ActiveSheet.Range("A1:AZ500")
If CurCell.Value = "Revision" Then CurCell.Interior.Color = RGB(0,204,0)
Next
End Sub
Or equivalently, you can probably use conditional formatting. Home Tab > Conditional Formatting > Highlight Cells Rules > Text that Contains. From there, type the value "Revision" into the value box and you can change the format of the cell to how you like it.

Paste text into a Word Document with a specific format

I'm working on a macro but I'm stuck at this point. I'm copying text from one word document to another, but I need this text to be pasted in a specific format, neither the source formatting, or it's destination's.
Is it possible to determine that the text I'll be pasting, gets pasted with a specific font, a specific size, and a specific color?
The easiest way to do this would be as follows:
Start recording a new macro.
Paste your text.
Select the pasted text.
Set the formatting (font, size, color) as you require.
Stop recording the macro.
Borrow heavily from the auto-generated selection and formatting code of the new macro for use in your original macro.

Word 2003 vba cannot change bookmark font

The following code does not work
objDoc.Bookmarks("SomeBookMark").Range.Font.Bold = True
objDoc.Bookmarks("SomeBookMark").Range.Text = GetSomeText()
objDoc.Bookmarks("SomeBookMark").Range.Font.Bold = True
When I run the code the text that is retrieved by GetSomeText() still has the default font.
Why don't you just style the bookmarks?
I searched for this in the past and also didn't find a proper solution back then.
However, since a bookmark represents a fixed field in a text template, usually the format shouldn't change so easily.
I'm sorry to put this in the reply field, but I can't find the "comment" button :-s