Hey guys I'm trying to set the name of a data series to something that contains Unicode characters, and I'm having a hell of a time. For instance, I want the series name to be this:
ε = n²-k²
I've looked at a handful of posts, but none (that I saw) had a similar situation. The fact that I'm new to Excel VBA scripts means that I have probably overlooked something simple. I know that the specific chart exists, because this bit of code is just something I've used before that worked with the addition of a few extra bits here and there. I keep getting the error "Runtime error (1004): Application defined or object-defined error." Here is what I have at the moment:
ActiveSheet.ChartObjects(1).Activate
Dim chart1 As String
chart1 = "= " & ChrW(&H3B5) & " = n" & ChrW(&HB2) & " - k" & ChrW(&HB2) & " 6-5-2012"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = chart1
ActiveChart.SeriesCollection(1).XValues = ActiveSheet.Range("F2:F602")
ActiveChart.SeriesCollection(1).Values = ActiveSheet.Range("N2:N602")
The debugger says that the following line is the cause of the error:
ActiveChart.SeriesCollection(1).Name = chart1
Is this what you are trying?
chart1 = ChrW(&H3B5) & " = n" & ChrW(&HB2) & " - k" & ChrW(&HB2) & " 6-5-2012"
You are getting that error because it is referring to it as a formula since it starts with an "=" sign
If you want to show the "=" sign then include a space before it. For example
chart1 = " = " & ChrW(&H3B5) & " = n" & ChrW(&HB2) & " - k" & _
ChrW(&HB2) & " 6-5-2012"
SNAPSHOT
A snapshot of both methods.
Related
I am trying to make this code work in vba excel however i keep receiving Expected End error
URL_Last = "&entry.7170534=" & EmpID & "&entry.634952910=" & EmpName & "&entry.1900852350=" & Gender & "&entry.776101390=" & Designation & "&entry.1211978069=" & Address & "&submit=Submit"
Form_URL = URL_First & URL_Last
May i ask what adjustment should i do inorder to fix this? Thanks
Months ago I wrote a small Makro for my Company and until now it worked just fine.
Recently (maybe because we updated Office Version) there is a bug, that excel adds a new line in a print statement.
Code:
outputString = value1 & " " & value2 & " " & value3 & " " & value4 & " " & value5 & " " & user & " " & date
used to give me this output:
22 S ***/***s 9932256 B*****t Fatma 811 R******r Alexander 27.12.2019
now gives me this output:
22 S ***/***s 9932256 B*****t Fatma 811 R******r Alexander
27.12.2019
As you can see, excel adds a newline.
Can somebody tell me what happends here?
EDIT:
Solution:
Excel adds the new line after using:
user = Application.UserName
Maybe this is due to the office update we had. So I just took substring and cut the last character and works fine now.
Application.Username returns as the documentation states the username. As it is Read/write it can indeed happen that you will get a username that contains a vbLf or vbCrLf. Have a look at the following example
Sub UserName_VbCrlf()
Dim origUser As String
Dim user As String
' Be careful when testing as it replaces your username!!
' Maybe you save it first
origUser = Application.UserName
Application.UserName = "Storax" & vbLf & "Home adress"
user = Application.UserName
' This will give different lengths
Debug.Print Len(user), Len(Replace(user, vbLf, ""))
' Restore original username
Application.UserName = origUser
End Sub
on my excel sheet the user can choose some video clips and arrange in different order to play as a vlc playlist. Unfortunately it can’t be guaranteed that the video file names haven’t any blanks.
To build the vlc playlist I use successfully:
Dim PL
PL = Shell("C:\Program Files\VideoLAN\VLC\VLC.exe " & certainPath & "\Movie6.flv" & " " & certainPath & "\Movie7.flv" & " " & certainPath & "\Movie8.flv ", 1)
'using "\Movie 6.flv" 'doesn't work of course
'using "\'Movie 6.flv'" 'doesn't work aswell
Is there another way to encapsulate file name with blanks?
thankfull for a hint.
Assuming that certainPath folder end with \ ( es. "C:\" ), this should work:
Dim PL
PL = Shell(chr(34) & "c:\Program Files\VideoLAN\VLC\vlc.exe " & chr(34) & chr(34) & certainPath & "Movie 6.flv" & chr(34) & " " & chr(34) & certainPath & "Movie 7.flv" & chr(34))
CHR is a function to returns the character from the ASCII table (the quotes in this case).
I have an issue, have an AutoCAD file with a ton of data links and would like to update only the data links related to a speciffic table.
Simmilar to the functionality of selecting a table with data links, right clicking and selecting Update Table Data Links.
i have the following code:
Private Sub Update_table_data_link(tblRef As AcadTable)
ThisDrawing.SendCommand "DATALINKUPDATE" & vbCr & "U" & vbCr & "K" & vbCr
End Sub
It works but updates all the data links in the drawing (which is a problem) so a perfect solution would either let me get what links are associated to tblRef
and change the line to:
ThisDrawing.SendCommand "DATALINKUPDATE" & vbCr & "U" & vbCr & "D" & vbCr & "datalink_name_from_tblRef" & vbCr
or directly send the command to update the links to tblRef
After much digging around and a lot of help, here is the answer:
Private Sub Update_table_data_link(tblRef As AcadTable)
ThisDrawing.SendCommand "DATALINKUPDATE " & vbCr & "U" & vbCr & Ent2lspEnt(tblRef) & vbCr & vbCr
End Sub
Public Function Ent2lspEnt(entObj As AcadEntity) As String
'Designed to work with SendCommand, which can't pass objects.
'This gets an objects handle and converts it to a string
'of lisp commands that returns an entity name when run in SendCommand.
Dim entHandle As String
entHandle = entObj.Handle
Ent2lspEnt = "(handent " & Chr(34) & entHandle & Chr(34) & ")"
End Function
note that "Update_table_data_link" has a table as input
I'm working with legacy code here and I'm not sure how much I could or should change, but I have code that looks for something like "SIC CODE 4000"
However the data html database I pull it from (we use a copy and paste) has updated their code to have:
"SiC CODE
4000"
Currently the code is:
Const strSic = "SIC Code "
However I now need it to add line breaks.
I tried modifying the code to say:
Const strSic = "SIC Code" & Chr(10) & Chr(10) & Chr(10)
But I get a compile error saying "Constant expression required"
I tried using "SIC Code \n\n\n" but maybe I'm not thinking the right character for line break.
Any suggestions?
The code for a new line is vbNewLine:
Const strSic = "SIC Code" & vbNewLine & vbNewLine & vbNewLine
Update:
To be a bit more detailed see the VBA constants:
vbNewLine = Chr(13)+Chr(10) on Windows and Chr(13) on Mac
vbCr = Chr(13)
vbLf = Chr(10)
So if you only need Chr(10) you should use vbLf (like Excel Hero's answer).
Try this:
Const strSic = "SIC Code" & vbLf & vbLf & vbLf
Yes vbNewLine is the correct code : )