Posts

Showing posts with the label vba

Delete and Rename a file using VBA

 Delete and Rename a file In VBA macro Excel To Delete a file using VBA script use Kill and a file name.           Kill "Filename.txt" To Rename a file use Name keyword and old file name and a new File name.           Name "Old" As "New"

VBA to create a file with utf-8 format

You can create any text or html file or any other file with utf-8 encryption. Dim TempFile As String   TempFile = "TempFileName.html"     Dim fsTrm As Object     Set fsTrm = CreateObject("ADODB.Stream") With fsTrm   .Type = 2             'Stream Type - we want Text Data.   .Charset = "utf-8"    'Specify Character Set.   .Open                 'Open the Stream And write Binary data to the Object   .WriteText "String"   .SaveToFile TempFile, 2      'Save Binary Data to Disk (Overwrite) End With

Excel Macros VBA to read data from a file and store into a string Variable

VBA to read data from a file In this vba script you can read text from Text, HTML, JS and any other file and store into a string variable. Dim oFSO As Object     Dim oFS As Object, sText As String     Set oFSO = CreateObject("Scripting.FileSystemObject")     Set oFS = oFSO.OpenTextFile(sFile)     Do Until oFS.AtEndOfStream         sText = oFS.ReadAll()     Loop     FileToString = sText          Set oFSO = Nothing     Set oFS = Nothing

How to get all red text from excel cell in vba string in a HTML format

Image
Private Sub CommandButton1_Click() Dim val As String val = Cells(5, "G").Value Dim fast As Boolean fast = True Dim last As Boolean last = False Dim values As String values = "" Dim lent As Integer lent = Len(val) Dim result As String result = "" For i = 1 To lent    If Cells(5, "G").Characters(Start:=i, Length:=1).Font.Color = vbRed Then       If fast Then         values = "<span style='color:#dd0062;'>" & "" & Mid(val, i, 1)         fast = False         last = True       Else        last = True        values = values & "" & Mid(val, i, 1)       End If