How can I add a - hyphen between the concatenated vales in this code: Worksheets("Start…
- User
How can I add a - hyphen between the concatenated vales in this code: Worksheets("Start Page").Cells(resultRow + 17, 2).Value = ws.Cells(i, "J").Value & ws.Range("B1").Value
- Assistant
To add a hyphen between the concatenated values, you can use the ampersand (&) symbol to combine them, like this:
Worksheets("Start Page").Cells(resultRow + 17, 2).Value = ws.Cells(i, "J").Value & " - " & ws.Range("B1").Value
This will insert a hyphen between the value in column J and the value in cell B1.
- User
In this code, I am getting an error that says =wdDoNotSaveChanges is not defined
Dim objWord As Object On Error Resume Next Set objWord = GetObject(, "Word.Application") If Err.Number <> 0 Then 'MsgBox "Microsoft Word is not open!", vbCritical, "Error" Exit Sub End If objWord.Quit SaveChanges:=wdDoNotSaveChanges Set objWord = Nothing - Assistant
The error message "wdDoNotSaveChanges is not defined" means that the VBA compiler does not recognize the constant "wdDoNotSaveChanges". This constant is part of the Microsoft Word Object Library, and if it is not included in your project, VBA cannot compile code that uses it.
To resolve the error, you need to add a reference to the Microsoft Word Object Library to your VBA project. Here are the steps to do this:
- In the VBA Editor, go to the "Tools" menu and select "References".
- Scroll down the list and look for "Microsoft Word x.x Object Library" (where x.x is the version of Word you have installed).
- Check the box next to this reference to select it.
- Click "OK" to close the dialog box and apply the changes.
Once you've added the reference, the VBA compiler should recognize the constant wdDoNotSaveChanges, and you should be able to compile and run your code without issues.