How to extract specific multiple text in SQL? - sql

I am trying to extract specific text from 1 column which seems to have concatenated several data points. Here is an example of part of the output that appears in 1 row:
[{"q":{"as":[{"id":"1","tags":[{"tagid":"62","tagstr":"Example1"},{"tagid":"3","tagstr":"Example1"},{"tagid":"65","tagstr":"Example1"},{"tagid":"71","tagstr":"Example1"}],"text":"Example1"}],"hidden":"false","id":"1","questionalias":"1","text":"Example1","ttl":"Example1"}},
The text in bold is what I am trying to extract. In practice each 'Example1' is selected from an option of words. Therefore I know exactly what text I am looking for. What I am struggling with is creating a way for the output to strip out the unwanted text and return the key words (around 8)
Alternatively, if someone has done something similar in VBA, that could also be an option.
Has anyone faced this before?

You can parse you data with Regex! It's marvelous!
There're plenty (Left, Mid, Right, Instr) functions to parse your data, right?
Some people, when confronted with a problem, think
“I know, I'll use regular expressions.”
Now they have two problems.
I think, that you trying to bound to some keywords(tagstr, text and ttl), so take a look at this.
Feel free to modify this expression, take a look on this and that!
In VBA there's no regex from scratch , so add VBA reference to "Microsoft VBScript Regular Expressions 5.5"
This is my exapmle with your data:
Sub test()
Dim Data As String
Dim Re As RegExp
Dim ReMatch As MatchCollection
Dim CurrentMatch As Match
Data = "[{" & Chr(34) & "q" & Chr(34) & ":{" & Chr(34) & "as" & Chr(34) & ":[{" & Chr(34) & "id" & Chr(34) & ":" & Chr(34) & "1" & Chr(34) & "," & Chr(34) & "tags" & Chr(34) & _
":[{" & Chr(34) & "tagid" & Chr(34) & ":" & Chr(34) & "62" & Chr(34) & "," & Chr(34) & "tagstr" & Chr(34) & ":" & Chr(34) & "Example1" & Chr(34) & "},{" & Chr(34) & "tagid" & Chr(34) & ":" & Chr(34) & "3" & Chr(34) & _
"," & Chr(34) & "tagstr" & Chr(34) & ":" & Chr(34) & "Example1" & Chr(34) & "},{" & Chr(34) & "tagid" & Chr(34) & ":" & Chr(34) & "65" & Chr(34) & "," & Chr(34) & "tagstr" & Chr(34) & ":" & Chr(34) & "Example1" & Chr(34) & _
"},{" & Chr(34) & "tagid" & Chr(34) & ":" & Chr(34) & "71" & Chr(34) & "," & Chr(34) & "tagstr" & Chr(34) & ":" & Chr(34) & "Example1" & Chr(34) & "}]," & Chr(34) & "text" & Chr(34) & ":" & Chr(34) & "Example1" & Chr(34) & _
"}]," & Chr(34) & "hidden" & Chr(34) & ":" & Chr(34) & "false" & Chr(34) & "," & Chr(34) & "id" & Chr(34) & ":" & Chr(34) & "1" & Chr(34) & "," & Chr(34) & "questionalias" & Chr(34) & ":" & Chr(34) & "1" & Chr(34) & _
"," & Chr(34) & "text" & Chr(34) & ":" & Chr(34) & "Example1" & Chr(34) & "," & Chr(34) & "ttl" & Chr(34) & ":" & Chr(34) & "Example1" & Chr(34) & "}},"
Debug.Print "My data is:" & vbNewLine & Data
Set Re = New RegExp
Re.IgnoreCase = True
Re.Global = True
Re.MultiLine = True
Re.Pattern = "(?=" & Chr(34) & "tagstr" & Chr(34) & "|" & Chr(34) & _
"text" & Chr(34) & "|" & Chr(34) & "ttl" & Chr(34) & ")(?:" & Chr(34) & _
"\w*" & Chr(34) & ":" & Chr(34) & "(.*?)" & Chr(34) & ")"
Debug.Print "My pattern is:" & vbNewLine & Re.Pattern
Set ReMatch = Re.Execute(Data)
Debug.Print "Matched " & ReMatch.Count & " times!"
For Each CurrentMatch In ReMatch
Debug.Print "Capture " & CurrentMatch.SubMatches(0) & " in " & CurrentMatch.Value
Next
End Sub
Output:
Not so complicated, right?
You can do this with standart string functions after all..

Related

SVG to display on button click event but how?

I have a textbox with some SVG code written in it and I would like to display it as my actual html page in a WebBrowser once the button click event is triggerd but I can see how to do that.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = "<!DOCTYPE html><html><body><svg height=" & Chr(34) & "5000" & Chr(34) & " width=" & Chr(34) & "5000" & Chr(34) & "><g style=" & Chr(34) & "fill:none;stroke:rgb(255,0,0);stroke-width:0.1" & Chr(34) & " stroke-dasharray=" & Chr(34) & "40,5,10,5" & Chr(34) & "><line x1=" & Chr(34) & "0" & Chr(34) & " y1=" & Chr(34) & "0" & Chr(34) & " x2=" & Chr(34) & "200" & Chr(34) & " y2=" & Chr(34) & "150" & Chr(34) & "/><line x1=" & Chr(34) & "200" & Chr(34) & " y1=" & Chr(34) & "150" & Chr(34) & " x2=" & Chr(34) & "400" & Chr(34) & " y2=" & Chr(34) & "0" & Chr(34) & "/><polyline points=" & Chr(34) & "0,0 50,50 0,100 50,100 130,150 210,190" & Chr(34) & "/></g></svg></body></html>"
WebBrowser1.Document.Write(TextBox1.Text)
End Sub

Using INSERT INTO with VALUES fails with Run-time error '3078'

I've been to dozens of sites. None address my particular question. All (including official Microsoft) tell me to do what I'm doing.
Dim strSQL As String
strSQL = """INSERT INTO tblVolunteers " & vbCrLf & _
"VALUES (" & [txtTitle] & "," & [txtFirstName] & "," & [txtMiddle] & "," & [txtLastName] & "," & [txtEmail] & _
"," & [txtPhone] & "," & [txtChurch] & "," & [txtGroup] & "," & [txtCouncil] & "," & [chkParCo] & "," & _
[txtMailAdd] & ");"""
CurrentDb.Execute strSQL
Here's what Microsoft has to say:
Run-time error '3078'
The Microsoft Access database engine cannot find the input table or query ""INSERT INTO tblVolunteers
VALUES (Mr.,John,L.,Smith,jlsmith#email.com,800-555-1212,St. Smith's,Smith,1234,-1,10 Smith St.
Smithville, TX 77777-3333);"". Make sure it exists and that its name is spelled correctly.
Why is it looking for a table or query when not only have I specified VALUES but it has picked up all the values from the form?
You could either use my function CSql and concatenate the values like this:
strSQL = "INSERT INTO tblVolunteers " & _
"VALUES (" & CSql([txtTitle]) & "," & CSql([txtFirstName]) & "," & CSql([txtMiddle]) & "," & _
CSql([txtLastName]) & "," & CSql([txtEmail]) & "," & CSql([txtPhone]) & "," & CSql([txtChurch] & "," & _
CSql([txtGroup]) & "," & CSql([txtCouncil]) & "," & CSql([chkParCo]) & "," & CSql([txtMailAdd]) & ");"
or you could skip this mess and use DAO for much cleaner coding and easier debugging:
Dim Records As DAO.Recordset
Dim Sql As String
Sql = "Select * From tblVolunteers"
Set Records = CurrentDb.OpenRecordset(Sql, dbOpenDynaset, dbAppendOnly)
Records.AddNew
Records!Title.Value = Me!txtTitle.Value
Records!FirstName.Value = Me!txtFirstName.Value
Records!Middle.Value = Me!txtMiddle.Value
Records!LastName.Value = Me!txtLastName.Value
Records!Email.Value = Me!txtEmail.Value
Records!Phone.Value = Me!txtPhone.Value
Records!Church.Value = Me!txtChurch.Value
Records!Group.Value = Me!txtGroup.Value
Records!Council.Value = Me!txtCouncil.Value
Records!ParCo.Value = Me!chkParCo.Value
Records!MailAdd.Value = Me!txtMailAdd.Value
Records.Update
Records.Close
Basically you need double quotes qaround the text, so for that you can use CHR(34)
strSQL = "INSERT INTO tblVolunteers " & vbCrLf & _
"VALUES (" & CHR(34) & [txtTitle] & CHR(34) & "," & CHR(34) & [txtFirstName] & CHR(34) & "," & CHR(34) & [txtMiddle] & CHR(34) & "," & CHR(34) & [txtLastName] & CHR(34) & "," & CHR(34) & [txtEmail] & CHR(34) & _
"," & CHR(34) & [txtPhone] & CHR(34) & "," & CHR(34) & [txtChurch] & CHR(34) & "," & CHR(34) & [txtGroup] & CHR(34) & "," & CHR(34) & [txtCouncil] & CHR(34) & "," & CHR(34) & [chkParCo] & CHR(34) & "," & CHR(34) & _
[txtMailAdd] & CHR(34) & ");"
use Access Query Design View..... start with just a single field, and then build field by field...
you can toggle it to SQl View to see the syntax

SQL String syntax error in VBA

I have this SQL string
theSQL = "INSERT INTO tbl_PROJECTS (co_id, contact_id, prop_id, worktype_id, incharge_id, project_name, project_ref," _
& "project_status, project_awardref, project_awarddate, project_startdate, project_targetdate," _
& "project_completedate, project_finalreportdate, project_location, project_notes)"
theSQL = theSQL & " VALUES (" & theCoID & "," & theContactID & "," & thePropID & "," & theWorkTypeID & "," & theInCharge & "," _
& "'" & theProjectName & "'" & "," & theProjectRef & "," & theProjectStatus & "," & theAwardRef _
& theAwardDate & "," & theStartDate & "," & theTargetDate & "," & theCompleteDate & "," & theFinalReportDate & "," _
& theLocation & "," & theNotes & ")"
When I do DoCmd.RunSQL (theSQL) I get syntax error (runtime error 3134).
I sent the output to Debug.Print. Can't find what is wrong with the syntax.
Anyone who can tell what is wrong with this sql command from VBA?
Some variables are null like thetargetdate and thecompletedate and I did not include the projectID in this query because it is autonumber. I want the number generated automatically.
Is it not allowed to pass null value to SQL?
Thanks
DEBUG PRINT RESULT :
INSERT INTO tbl_PROJECTS (co_id, contact_id, prop_id, worktype_id,
incharge_id, project_name, project_ref, project_status,
project_awardref, project_awarddate, project_startdate,
project_targetdate, project_completedate, project_finalreportdate,
project_location, project_notes) VALUES (61,66,134,1,1,'STRUCTURAL
DESIGN',,AWARDED,Test LPO,2/11/2016,,,,,Dnata 4 storey warehouse,)
Is it not allowed to pass null value to SQL?
It is, but it can't be done by stating a space. You must write Null:
VALUES (61,66,134,1,1,'STRUCTURAL DESIGN',Null,'AWARDED','Test LPO',#2/11/2016#,Null,Null,Null,Null,'Dnata 4 storey warehouse Alquoz',Null)
and quotes and date delimiters are missing.
You wrote this:
theSQL = "INSERT INTO tbl_PROJECTS (co_id, contact_id, prop_id, worktype_id, incharge_id, project_name, project_ref," _
& "project_status, project_awardref, project_awarddate, project_startdate, project_targetdate," _
& "project_completedate, project_finalreportdate, project_location, project_notes)"
theSQL = theSQL & " VALUES (" & theCoID & "," & theContactID & "," & thePropID & "," & theWorkTypeID & "," & theInCharge & "," _
& "'" & theProjectName & "'" & "," & theProjectRef & "," & theProjectStatus & "," & theAwardRef _
& theAwardDate & "," & theStartDate & "," & theTargetDate & "," & theCompleteDate & "," & theFinalReportDate & "," _
& theLocation & "," & theNotes & ")"
In the second line in the second block, there's no ending quotes.

Put formula with if statements in the entire columns

I have recorded a macro with the following formula, but it gives me an error in the second line.
Expected end of statement.
I guess the issue is that its way to long. Please suggest how to make this work?
Sub Macro1()
Range("CG2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC69=""High"",(IF(AND(RC4<>"""",RC5<>"""",RC6<>"""",RC7<>"""",RC8<>"""",RC10<>"""",RC11<>"""",RC12<>"""",RC13<>"""",RC14<>"""",RC16<>"""",RC17<>"""",RC18<>"""",RC19<>"""",RC20<>"""",RC21<>"""",RC22<>"""",RC23<>"""",RC24<>"""",RC25<>"""",RC26<>"""",RC27<>"""",RC28<>"""",RC29<>"""",RC30<>"""",RC31<>"""",RC32<>"""",RC33<>"""",RC34<>"""",RC35<>"""",RC36<>"""",RC37<>"""",RC38<>"""",RC39<>"""",RC40<>"""",RC41<>"""",RC42<>"""",RC43<>"""",RC44<>"""",RC45<>"""",RC46<>""""),""No"",""Yes""))," & Chr(10) & "(IF(RC69=""Medium"",(IF(AND(RC4<>"""",RC5<>"""",RC6<>"""",RC7<>"""",RC8<>"""",RC10<>"""",RC11<>"""",RC12<>"""",RC13<>"""",RC14<>"""",RC16<>"""",RC17<>"""",RC18<>"""",RC19<>"""",RC20<>"""",RC21<>"""",RC22<>"""",RC23<>"""",RC31<>"""",RC32<>"""",RC33<>"""",RC34<>"""",RC35<>"""",RC36<>"""",RC37<>"""",RC38<>"""",RC39<>"""",RC40<>"""",RC41<>"""",RC42<>"""",RC44<>"""",RC45<>"""",RC46<>""""),""No"",""Yes""))," & Chr(10) & "(IF(AND(RC4<>"""",RC5<>"""",RC6<>"""",RC7<>"""",RC8<>"""",RC10<>"""",RC11<>"""",RC12<>""""
""",RC14<>"""",RC16<>"""",RC17<>"""",RC18<>"""",RC19<>"""",RC20<>"""",RC31<>"""",RC32<>"""",RC33<>"""",RC34<>"""",RC35<>"""",RC36<>"""",RC37<>"""",RC38<>"""",RC39<>"""",RC41<>"""",RC42<>"""",RC45<>"""",RC46<>""""),""No"",""Yes"")))))"
End Sub
The issue here is the multiples ", and you also have a different kind of these : “ which do not work!
So replace the " by Chr(34) like this :
Sub formula()
Range("CO2:CO").formula = "=IF(OR(LEN($BN2)=0;$BN2=" & Chr(34) & "Not Performed" & Chr(34) & _
";LEN($BK2)=0;$BK2=" & Chr(34) & "Not Performed" & Chr(34) & _
";LEN($BL2)=0;$Q2=" & Chr(34) & "Not Performed" & Chr(34) & _
";LEN($BM2)=0);" & Chr(34) & "Yes" & Chr(34) & ";" & Chr(34) & _
"No" & Chr(34) & ")"
End Sub

How to add an incremental count (version) to a string (file) in Excel/VBA?

I have tried a lot of different things, and it seems like I cannot get it to work. So basically, this is a small piece of my complete code.
I am using Microsoft Scripting Runtime to save the file, using the FileExists() to check if the file actually exist before saving.
This is working fine if I remove the IF-statement/Loop.
However, now it feels like FileExists won´t find the string, MyFilePath, when I run it with the IF/Loop. (getdirsubparentpath is a function)
Dim week, UserName As String
Dim MyFile, MyFilePath As String
Dim version As Integer
' Current week, XX
week = Format(Date, "ww")
' Username, e.g. niclas.madsen
UserName = Environ$("UserName")
' Initials, first letter of last and surname to caps
' e.g. niclas.madsen would be NM
UserName = UCase(Left(UserName, 1) & Mid(UserName, InStr(UserName, ".") + 1, 1))
' fix filename for saving purpose
MyFile = Replace(Replace("SupplierOrganization_W", "", ""), ".", "_") _
& "" _
& week _
& " " _
& UserName _
& ".csv"
'SupplierOrganization_WXX NM
MyFilePath = getDirSubParentPath & MyFile
' Look for the MyFilePath, if it exists then
' Add "-1" after the week number, if 1 exists, add 2, etc.
If Len(Dir(MyFilePath)) <> 0 Then
version = 0
Do
version = version + 1
MyFilePath = Dir(getDirSubParentPath & "SupplierOrganization_W" & week & "-" & version & " " & UserName & ".csv")
Loop Until Len(Dir(MyFilePath)) < 0
End If
Dim tmpFile, tmpFilePath As String
tmpFile = getDirSubParentPath & "tmp_file.txt"
Dim tmpString As String
'Dim fso As New FileSystemObject
Dim fso As Object 'scripting.filesystemobject
Set fso = CreateObject("scripting.filesystemobject")
If fso.FileExists(MyFilePath) = True Then
Application.ScreenUpdating = False
Open MyFilePath For Input As #1
Open tmpFile For Output As #2
tmpString = Input(LOF(1), 1) 'read the entire file
tmpString = Replace(tmpString, (Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) _
& Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) _
& Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) _
& Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) _
& Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) _
& Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) _
& Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) _
& Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) _
& Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) _
& Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) _
& Chr(34)), "") 'eliminate double quotation and commas in the first line with UTF-8
Print #2, tmpString 'output result
Close #1
Close #2
fso.DeleteFile (MyFilePath) 'delete original file
fso.CopyFile tmpFile, MyFilePath, True 'rename temp file
fso.DeleteFile (tmpFile) 'delete temp file
Application.ScreenUpdating = True
MsgBox "Finished processing file", vbInformation, "Done!"
Else
MsgBox "Cannot locate the file : " & MyFilePath, vbCritical, "Error"
End If
Set fso = Nothing
End Sub
' Get Parent Sub Directory Path
Function getDirSubParentPath()
getDirSubParentPath = ThisWorkbook.Path & Application.PathSeparator & "CSV" & Application.PathSeparator & "Parent" & Application.PathSeparator
End Function
I finally manage to create a solution that seems viable. However, the code could use some cleaning up :) But it gets the job done.
So basically, I am having some issues with the loop. It will return a file named W16-0 (which should actual just be W16). It should only add the "-X" if W16 is found. So the incremental order should be W16, W16-1, W16-2, etc.
What I am doing is that I try to locate if there is a W16-0 and then replace it with W16. Furthermore, it seems like the loop will give me one higher than the amount of files I have. So that is where I also got an error. So if I had a W16-4, it would ask the macro to find and open a file named W16-5, which would obviously not exist.
If somebody could help me clean up the code, I would be really thankful!
Sub RemoveCommasDoubleQ()
'
' Enable a reference to 'Microsft Scripting Runtime'
' under VBA menu option Tools > References
Dim week, UserName As String
Dim MyFile, MyFilePath As String
Dim version As Integer
Dim fso As Object 'scripting.filesystemobject
Set fso = CreateObject("scripting.filesystemobject")
' Current week, XX
week = Format(Date, "ww")
' Username, e.g. niclas.madsen
UserName = Environ$("UserName")
' Initials, first letter of last and surname to caps
' e.g. niclas.madsen would be NM
UserName = UCase(Left(UserName, 1) & Mid(UserName, InStr(UserName, ".") + 1, 1))
' fix filename for saving purpose
MyFile = Replace(Replace("SupplierOrganization_W", "", ""), ".", "_") _
& "" _
& week _
& " " _
& UserName _
& ".csv"
'SupplierOrganization_WXX NM
'MyFilePath = ThisWorkbook.Path & "\CSV\Parent\" & MyFile
MyFilePath = getDirSubParentPath & MyFile
Debug.Print MyFilePath
Debug.Print "BEFORE LOOP"
'version = 1
Do While Len(Dir(MyFilePath)) <> 0
'// If it does, then append a _000 to the name
'// Change _000 to suit your requirement
MyFilePath = getDirSubParentPath & "SupplierOrganization_W" & week & "-" & version & " " & UserName & ".csv"
'// Increment the counter
version = version + 1
'// and go around again
If MyFilePath = getDirSubParentPath & "SupplierOrganization_W" & week & "-0" & " " & UserName & ".csv" Then
MyFilePath = getDirSubParentPath & "SupplierOrganization_W" & week & " " & UserName & ".csv"
Debug.Print MyFilePath
Debug.Print "IF LOOP"
End If
Loop
Debug.Print MyFilePath
Debug.Print "LOOP"
If fso.FileExists(getDirSubParentPath & "SupplierOrganization_W" & week & "-" & version & " " & UserName & ".csv") = False Then
MyFilePath = getDirSubParentPath & "SupplierOrganization_W" & week & "-" & version - 2 & " " & UserName & ".csv"
MsgBox getDirSubParentPath & "SupplierOrganization_W" & week & "-" & version & " " & UserName & ".csv"
End If
fileName = fso.GetFileName(MyFilePath)
Debug.Print fileName
If MyFilePath = getDirSubParentPath & "SupplierOrganization_W" & week & "-0" & " " & UserName & ".csv" Then
MyFilePath = getDirSubParentPath & "SupplierOrganization_W" & week & " " & UserName & ".csv"
Debug.Print MyFilePath
Debug.Print "her it should be 0"
End If
If MyFilePath = getDirSubParentPath & "SupplierOrganization_W" & week & "-" & " " & UserName & ".csv" Then
MyFilePath = getDirSubParentPath & "SupplierOrganization_W" & week & "-" & version & " " & UserName & ".csv"
End If
Debug.Print "HER ER VI"
fileName = fso.GetFileName(MyFilePath)
Debug.Print fileName
Dim tmpFile, tmpFilePath As String
tmpFile = getDirSubParentPath & "tmp_file.txt"
Dim tmpString As String
Debug.Print "------"
Debug.Print MyFilePath
If fso.FileExists(getDirSubParentPath & "SupplierOrganization_W" & week & "-0" & " " & UserName & ".csv") = True Then
MsgBox "Found the W-0"
MyFilePath = getDirSubParentPath & "SupplierOrganization_W" & week & " " & UserName & ".csv"
End If
Debug.Print "Found 0?"
Debug.Print MyFilePath
If fso.FileExists(MyFilePath) = True Then
Application.ScreenUpdating = False
Open MyFilePath For Input As #1
Open tmpFile For Output As #2
tmpString = Input(LOF(1), 1) 'read the entire file
tmpString = Replace(tmpString, (Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) _
& Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) _
& Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) _
& Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) _
& Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) _
& Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) _
& Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) _
& Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) _
& Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) _
& Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & Chr(44) & Chr(34) _
& Chr(34)), "") 'eliminate double quotation and commas in the first line with UTF-8
Print #2, tmpString 'output result
Close #1
Close #2
fso.DeleteFile (MyFilePath) 'delete original file
fso.CopyFile tmpFile, MyFilePath, True 'rename temp file
fso.DeleteFile (tmpFile) 'delete temp file
Application.ScreenUpdating = True
MsgBox "Finished processing file", vbInformation, "Done!"
Else
MsgBox "Cannot locate the file : " & MyFile, vbCritical, "Error"
End If
Set fso = Nothing
End Sub