I have some specific things I need to automatically bold and am having issues coming up with the right code for this... Below is an example:
Product Name:
Customer Account/Name:
Description of Issue:
So, what I need is only bold the above and nothing after the ":", example:
Product Name: Tech Tools
Customer Account/Name: Federation of Planets
Description of Issue: NCC-1701 leaking
So, all of my VBA experience comes from Excel... Which I stupidly started this in excel and then realized that wouldn't work and was like "Oh, I can just use my vba from Excel in Word!" No... no I can't...
Here is my Excel VBA:
Sub Find_and_Bold()
Dim rCell As Range, sToFind As String, iSeek As Long
Dim Text(1 To 33) As String
Dim i As Integer
Text(1) = "Product Name:"
Text(2) = "Project ID and/or URL:"
Text(3) = "Permission to join project?"
Text(4) = "Permission to join Account as Admin?"
Text(5) = "No. of Users on Project:"
Text(6) = "Company/Account Name:"
Text(7) = "Reported by:"
Text(8) = "Reporting User Role in Project:"
Text(9) = "Platform, Version, OS Version:"
Text(10) = "Which platform does this organization/user mainly use?"
Text(11) = "Can the agent repro in test project?"
Text(12) = "Is this related to a third-party integration? (If so, please provide name):"
Text(13) = "What is the company and project name in the third-party software?"
Text(14) = "Has the reporter been able to perform this action with no issues in the past?"
Text(15) = "Pype-Spec Version Name (if applicable):"
Text(16) = "Salesforce ID:"
Text(17) = "Description of Issue:"
Text(18) = "Steps to Reproduce:"
Text(19) = "1."
Text(20) = "2."
Text(21) = "3."
Text(22) = "4."
Text(23) = "Expected Behavior:"
Text(24) = "Observed Behavior"
Text(25) = "Additional Observation/Notes"
Text(26) = "Company/Account name:"
Text(27) = "Can the agent repro in customer project?"
Text(28) = "Is this related to a third party integration?"
Text(29) = "Pype-Spec version name (if applicable):"
Text(30) = "Has the customer provided screenshots/screen- recordings?"
Text(31) = "Description of issue:"
Text(32) = "# of Users on Project:"
Text(33) = "# of Users on Project:"
For Each rCell In Range("A1:A100")
For i = LBound(Text) To UBound(Text)
sToFind = Text(i)
iSeek = InStr(1, rCell.Value, sToFind)
Do While iSeek > 0
rCell.Characters(iSeek, Len(sToFind)).Font.Bold = True
iSeek = InStr(iSeek + 1, rCell.Value, sToFind)
Loop
Next i
Next rCell
Call DeleteBlankRows
End Sub
It seems to me you could do the lot without VBA, just using a wildcard Find/Replace, where:
Find = [!^13]#[:\?.]
Replace = ^&
and:
Find = [!^13][1-4].
Replace = ^&
with the replacement font attribute set to Bold or, better still, to the 'Strong' character Style.
The only string that might be missed is 'Observed Behavior' - because in your code it lacks a terminating ':'.
The above can, of course, be turned into VBA.
Related
I have a dataset that contains multiple values. I want to take those rows from that dataset that contains "the specific value" and firstly I want to display those in a MessageBox.
Furtheron, I try to view them in a datagridview called ErrorsDgV.
I already searched this topic and found a good function, but unfortunately, all I get from the MessageBox is an empty box.
ErrorsDgV.DataSource = Srchdataset.Tables("blubb")
LineLabel.Text = "Lines: " &
Srchdataset.Tables("blubb").Rows.Count.ToString
ErrorsDgV.Sort(ErrorsDgV.Columns(1), System.ComponentModel.ListSortDirection.Ascending)
ErrorsDgV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
ErrorsDgV.Columns(1).DefaultCellStyle.Format = "dd/MM/yyyy HH:mm:ss.fff"
Dim answer As String = ""
Dim SearchRows() As Data.DataRow
SearchRows = Srchdataset.Tables("blubb").Select("Data = 'the specific value'")
answer = ""
For k As Integer = 0 To SearchRows.Length - 1
If answer = "" Then
answer = SearchRows(k).Item("Data")
Else
answer = answer & vbNewLine & SearchRows(k).Item("Data")
End If
Next
MsgBox(" " & answer)
I debugged also and got to know that SearchRows is empty, even if the specific value is inlcuded in that DataSet.
I am having some issue with a value that is being determined from some VBA code in my Access tool. I am quite a beginner with VBA and this code was developed alongside a very experienced VBA programmer (who has gone away hence is unable to assist me).
This is the code in question:
Private Sub ValidatePrinting()
Dim rst As DAO.Recordset, PrintMethodVal As Boolean, PracIdVal As Long, datePrintedcol As String, PrintedCount As Integer, ImportedCount As Integer
Dim fromtxt As String, wheretxt As String, conditionalImportedCount As Integer, PrintConditions As Boolean
PrintMethodVal = Me.filter_PrintMethod.Value
PracIdVal = Me.filter_PracticeID.Value
datePrintedcol = Me.filter_LetterRound.Value
datePrintedcol = IIf(datePrintedcol = "1st Round", "datePrinted_1st", IIf(datePrintedcol = "2nd Round", "datePrinted_2nd", ""))
PrintedCount = Me.filter_LetterCount.Value
PrintConditions = Me.filter_PrintConditions.Value
If (datePrintedcol = "") Then
Call DisplayMessage("All letters already sent")
Else
fromtxt = " tbl_main_ListLog as T INNER JOIN tbl_dbextract_GPPractice as GPP ON T.GPPracticeID = GPP.Id"
wheretxt = PrintSQLCriteria(PracIdVal, datePrintedcol)
Set rst = CurrentDb.OpenRecordset(PrintValidationSQL(PrintMethodVal, fromtxt, wheretxt))
ImportedCount = rst.Fields(0).Value
conditionalImportedCount = rst.Fields(1).Value
If ImportedCount = conditionalImportedCount Then
If ImportedCount = PrintedCount Then
If PrintMethodVal = PrintConditions Then
tb_Result = "All OK"
CurrentDb.Execute (" update " & fromtxt & " set " & datePrintedcol & " = date() " & wheretxt)
Else
tb_Result = "Wrong print method selected"
End If
Else
tb_Result = "Counts don't match"
End If
Else
tb_Result = "Mismatched print conditions"
End If
End If
End Sub
So the issue is, when the PrintMethodVal does not equal PrintConditions it outputs "Mismatched Print conditions" as opposed to the "Wrong print method selected" which is what it should. It also outputs "Mismatched Print conditions" when the ImportedCount also does not equal the PrintedCount (as well as the first situation), which is weird as the If should end there and output "Counts don't match".
This code was functioning correctly when originally developed, but I had to include the check for PrintMethodVal = PrintConditions.
What am I missing here?
I have a rather interesting problem going on in my excel problem. Basically I have two Workbooks, lets say
ACTIVE.xlsm and EXTERNAL.xls
Active has a macro that opens external and drops in some data from active, then reads a solution on external and returns it to the user on the active workbook. Whew. Thats a tough one. Now that we're through that, heres the problem. It is my personal opinion that there is a glitch in external (which I'm unable to fix as its a company read-only file) that when active drops in its data into a specific drop-down (data validation) cell (other data validation cells work fine with this macro, its only this one that doesn't), the solution cell on external doesnt update, but rather jumps to "#N/A". At this point, my VBA has run into a bug, and the code stops with external still open. When I look at external, I've deduced that this singular variable cell is the problem amdist all the other variable cells determining the solution.
The variable cell at this point contains the number "150" and although the data validation allows for this option, the solution cell still says "#N/A". It isn't until I physically click inside of the cell with "150" like I'm going to edit it, then I press enter, that the #N/A corrects to the appropriate solution (Let's say this solution is "$352.08") Keep in mind, the value within the variable cell never changed, it perhaps only was "refreshed".
Any ideas as to why this is happening? I know this is long-winded, but I suppose that's why I have been unable to find a solution thus far. Perhaps there's a VBA workaround that can simulate clicking in the cell, then pressing enter, who knows!
Thanks in advance!
Here's some code for funsies, though I don't believe this is a code issue, as it works for all other "external"'s that I've been working with.
...ElseIf Left(Range("C9").Value, 4) = "LA23" Then
CurWkbk = ActiveWorkbook.Name
PartNo = Worksheets("LINAK ONE").Range("C6").Value
PartNoID_B = Worksheets("GPL Pull").Range("B8").Value
PartNoID_C = Worksheets("GPL Pull").Range("C8").Value
PartNoID_D = Worksheets("GPL Pull").Range("D8").Value
PartNoID_E = Worksheets("GPL Pull").Range("E8").Value
PartNoID_F = Worksheets("GPL Pull").Range("F8").Value
PartNoID_G = Worksheets("GPL Pull").Range("G8").Value
PartNoID_H = Worksheets("GPL Pull").Range("H8").Value
PartNoID_I = Worksheets("GPL Pull").Range("I8").Value
PartNoID_J = Worksheets("GPL Pull").Range("J8").Value
PartNoID_K = Worksheets("GPL Pull").Range("K8").Value
Workbooks.Open ("EXTERNAL.xls")
Workbooks("EXTERNAL.xls").Sheets("Price").Activate
Range("E9").Value = PartNoID_B
Range("G9").Value = PartNoID_C
Range("I9").Value = PartNoID_D
Range("K9").Value = PartNoID_E
Range("M9").Value = PartNoID_F
Range("O9").Value = PartNoID_G
Range("Q9").Value = PartNoID_H
Range("S9").Value = PartNoID_I
Range("S9").Select
ActiveCell.Calculate
Range("U9").Value = PartNoID_J
Range("W9").Value = PartNoID_K
Range("AD7").Value = "LUS"
LUSPrice = Range("AE9").Value
Range("AD7").Value = "USD"
USDPrice = Range("AE9").Value
Range("AD7").Value = "DKK"
DKKPrice = Range("AE9").Value
Windows(CurWkbk).Activate
ActiveWorkbook.Sheets("Discount Calculator").Activate
Range("D5").Value = LUSPrice
ActiveWorkbook.Sheets("PRICE GENERATOR").Activate
Range("C25").Value = PartNo & " Pricing | LUS: $" & Round(LUSPrice, 2) & " | USD: $" & Round(USDPrice, 2) & " | DKK: kr " & Round(DKKPrice, 2)
MsgBox "Tillykke! Pricing for the " & PartNo & " has been generated. The price has been entered into the discount calculator.", , "Pricing Generated"
Workbooks("EXTERNAL.xls").Close False...
you should be using fully qualified references to cells
this is a rewrite of your code
...ElseIf Left(Range("C9").Value, 4) = "LA23" Then ' which workbook/sheet ????
CurWkbk = ActiveWorkbook.Name ' which workbook ????
PartNo = Worksheets("LINAK ONE").Range("C6").Value ' which workbook ????
With Worksheets("GPL Pull")
PartNoID_B = .Range("B8").Value
PartNoID_C = .Range("C8").Value
PartNoID_D = .Range("D8").Value
PartNoID_E = .Range("E8").Value
PartNoID_F = .Range("F8").Value
PartNoID_G = .Range("G8").Value
PartNoID_H = .Range("H8").Value
PartNoID_I = .Range("I8").Value
PartNoID_J = .Range("J8").Value
PartNoID_K = .Range("K8").Value
End With
Workbooks.Open ("EXTERNAL.xls")
With Workbooks("EXTERNAL.xls").Worksheets("Price")
.Range("E9").Value = PartNoID_B
.Range("G9").Value = PartNoID_C
.Range("I9").Value = PartNoID_D
.Range("K9").Value = PartNoID_E
.Range("M9").Value = PartNoID_F
.Range("O9").Value = PartNoID_G
.Range("Q9").Value = PartNoID_H
.Range("S9").Value = PartNoID_I
.Range("S9").Calculate
.Range("U9").Value = PartNoID_J
.Range("W9").Value = PartNoID_K
.Range("AD7").Value = "LUS"
LUSPrice = .Range("AE9").Value
.Range("AD7").Value = "USD"
USDPrice = .Range("AE9").Value
.Range("AD7").Value = "DKK"
DKKPrice = .Range("AE9").Value
End With
CurWkbk.Worksheets("Discount Calculator").Range("D5").Value = LUSPrice ' which workbook ????
CurWkbk.Worksheets("PRICE GENERATOR").Range("C25").Value = PartNo & " Pricing | LUS: $" & Round(LUSPrice, 2) & " | USD: $" & Round(USDPrice, 2) & " | DKK: kr " & Round(DKKPrice, 2)
MsgBox "Tillykke! Pricing for the " & PartNo & " has been generated. The price has been entered into the discount calculator.", , "Pricing Generated"
Workbooks("EXTERNAL.xls").Close False...
This code should translate all the words from it's dictionary in a cell, but instead, it translates only the first line (it only translates "E" to "And"), it should go through all the words and change all the words in the cell.
Sub traducaobeta2()
Dim translate As Object 'scritping.Dictionary
Set translate = CreateObject("Scripting.Dictionary")
translate("e") = "and"
translate("Telefones") = "Telephones"
translate("Livros") = "Books"
translate("Criado mudo") = "Night stand"
translate("Banqueta") = "Stool"
translate("livros") = "books"
translate("cadernos") = "papers"
translate("travesseiros") = "pillows"
translate("Mesa") = "Table"
translate("Materiais de escritório") = "Office materials"
' the list goes on...
Dim Words As Variant
Dim I As Integer
Words = Split(LCase(activecell.Value))
For I = LBound(Words) To UBound(Words)
If translate(Words(I)) <> "" Then Words(I) = translate(Words(I))
Next
activecell.Value = Join(Words)
activecell.Value = Ucase$(Left$(activecell.Value, 1)) & Right$(activecell.Value, Len(activecell.Value) - 1)
end sub
When you use Split() like this it puts each word into the array but changes them to lower case. The keys in the dictionary are case sensitive and so you need to use lower case keys instead.
translate("e") = "and"
translate("telefones") = "Telephones"
translate("livros") = "Books"
translate("criado mudo") = "Night stand"
translate("banqueta") = "Stool"
translate("livros") = "books"
translate("cadernos") = "papers"
translate("travesseiros") = "pillows"
translate("mesa") = "Table"
translate("materiais de escritório") = "Office materials"
' the list goes on...
on a side note, that last one ("materiais de escritório") will never work because it has spaces in so your array will have materiais, de and escritório in separate indexes and will never match the dictionary key.
In addition to Macro Man's excellent comments, another approach is to completely ignore the LCase, UCase issue. Do not attempt to change or fix cases at all. Instead just beef-up the translate object like:
translate("livros") = "books"
translate("Livros") = "Books"
If the source text has proper capitalization, the translate will work and if the source text is all lower case, the translate should work.
i need to import test from excel to hp qc test this is my:
Set TestFactory = QCconn.TestFactory
Set testObj = TestFactory.AddItem(Null)
testObj.Field("TS_USER_14") = "1" 'Arml
testObj.Field("TS_USER_01") = "TDB" 'Module
testObj.Field("TS_USER_13") = "3" 'Policy Status
testObj.Field("TS_USER_15") = "4" 'Project
testObj.Field("TS_SUBJECT") = "אוטומציה" 'Subject
testObj.Field("TS_NAME") = "ניסיון1" 'Test Name
testObj.Field("ST_DESCRIPTION") = "2"
testObj.Field("TS_RESPONSIBLE") = "zvikav" 'Designer
testObj.Field("TS_USER_12") = "6" 'Policy Type
testObj.Field("TS_USER_11") = "עדיף" ' Product154981
testObj.DesignStepFactory.Fields("DS_STEP_NAME") = "ניסיון"
testObj.Post
i can to upload the test but i cant do a test step
how i upload the DesignSteps?
You need to add a new item after getting the DesignStepFactory:
' Get the DesignStepFactory from the test.
Set DSFactory = testObj.DesignStepFactory
' Create the new design step.
Set desstep = DSFactory.AddItem(Null)
' Set step properties and post step
desstep.StepName = "Step one"
desstep.StepDescription = "Do something"
desstep.StepExpectedResult = "Expect something"
desstep.Post
Not sure whether it is important to first post your test object before adding the step. But I'm sure you'll find out.