Sub InsertPicture()
With ActiveSheet.PageSetup.CentertFooterPicture
.FileName = "C:\Sample.jpg"
.Height = 275.25
.Width = 463.5
.Brightness = 0.36
.ColorType = msoPictureGrayscale
.Contrast = 0.39
.CropBottom = -14.4
.CropLeft = -28.8
.CropRight = -14.4
.CropTop = 21.6
End With
' Enable the image to show up in the left header.
ActiveSheet.PageSetup.LeftHeader = "&G"
' Enable the image to show up in the center footer.
ActiveSheet.PageSetup.CenterFooter = "&G"
End Sub
Applied Knowledge
ASP.NET Core, SQL Server, Excel & Access VBA, JavaScript and SAS
Wednesday, June 24, 2026
VBA Excel - Add Picture from a folder into Excel sheet header
PageSetup object (Excel)Represents the page setup description.The PageSetup object contains all page setup attributes (left margin, bottom margin, paper size, and so on) as properties.
The following example adds a picture titled Sample.jpg from the C:\ drive to the left section of the header. This example assumes that a file called Sample.jpg exists on the C:\ drive.
VBA Word - Convert Multiple HTML pages into Markdown, MD files
Run the following VBA Excel program. The program opens chat.html file from source folder in default browser. Then it selects all its content and paste into a text file. The text file is named the folder name with file extension .md and saved into the parent folder. This process is repeated for all subfolders of the parent folder.
Private Sub ConvertChatHtmlToMarkdown_NoWarnings(sourceFolder As String)
Dim fso As Object
Dim chatFilePath As String
Dim parentFolder As String
Dim folderName As String
Dim markdownFilePath As String
Dim htmlContent As String
Dim ts As Object
Dim shellCommand As String
' Ensure sourceFolder ends without trailing backslash
If Right(sourceFolder, 1) = "\" Then
sourceFolder = Left(sourceFolder, Len(sourceFolder) - 1)
End If
chatFilePath = sourceFolder & "\chat.html"
' Check if chat.html exists
If Dir(chatFilePath) = "" Then
Debug.Print "chat.html not found in: " & sourceFolder
Exit Sub
End If
' Open chat.html in default browser silently without FollowHyperlink
shellCommand = "cmd /c start """" """ & chatFilePath & """"
Shell shellCommand, vbHide
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Read HTML content
Set ts = fso.OpenTextFile(chatFilePath, 1, False, -2)
htmlContent = ts.ReadAll
ts.Close
' Get folder and parent folder names
folderName = fso.GetFolder(sourceFolder).Name
parentFolder = fso.GetFolder(sourceFolder).parentFolder.Path
markdownFilePath = parentFolder & "\" & folderName & ".md"
' Write to .md file
Set ts = fso.CreateTextFile(markdownFilePath, True, True)
ts.Write htmlContent
ts.Close
Debug.Print "Converted: " & folderName & " -> " & markdownFilePath
End Sub
Sub ProcessAllChats()
Dim fso As Object
Dim sourceFolderPath As String
Dim sourceFolder As Object
Dim subfolder As Object
Set fso = CreateObject("Scripting.FileSystemObject")
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Root Folder Containing Chat Folders"
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub ' User cancelled
sourceFolderPath = .SelectedItems.Item(1)
End With
Set sourceFolder = fso.GetFolder(sourceFolderPath)
For Each subfolder In sourceFolder.SubFolders
ConvertChatHtmlToMarkdown_NoWarnings subfolder.Path
Next
MsgBox "All chat.html files processed.", vbInformation
End Sub
Subscribe to:
Posts (Atom)
Hot Topics
-
In previous post , we learnt basic introduction to SQL Server . In this post we will learn about SSMS (SQL Server Management Studio) softwar...
-
In the previous post we have learnt about SSMS (SQL Server Management Studio) and how to connect with a SQL Server instance. In this post w...
-
By Ajeet Kumar RADAR CHART In radar chart, the categorical variable is displayed as spikes radiating from a central point. The values o...