I am trying to insert text and pictures from a specific folder to a hidden Excel file, in specific cells, but for some reason I do not succeed in adding the pictures to the file.
What I can is open a hidden Excel file and add a bunch of data to the Excel. I can also add pictures tot the Excel from which the VBA script is running. However combining both is something where I fail.
I use the following code to open an Excel file and put data in there:
Dim ExcelFileName As String
ExcelFileName = "C:\PictureTest.xlsx"
Dim Workbook As New Excel.Application
Dim DataWorkbook As New Excel.Workbook
Set DataWorkbook = Workbook.Workbooks.Open(ExcelFileName)
Workbook.Sheets("Sheet1").Cells(1, 1) = "Data to CELL"
DataWorkbook.Save
DataWorkbook.Close
Set Workbook = Nothing
Set DataWorkbook = Nothing
This one works perfectly, I can put data in any sheet anywhere I want. However I also need to put pictures on certain sheets/cells.
I use the following code to add a picture to the active Excel file from which I am running the VBA script:
Dim PicturePath As String
PicturePath = "C:\Picture.tif"
Dim strPath As String
Dim Picture As Object
Set Picture = ActiveSheet.Pictures.Insert(PicturePath)
Picture.ShapeRange.LockAspectRatio = msoCTrue
Picture.Placement = xlMoveAndSize
Picture.ShapeRange.Width = 0.3 * Picture.Width
Is there anyone who can help me in getting both combined?
What I can is open a hidden Excel file and add a bunch of data to the Excel. I can also add pictures tot the Excel from which the VBA script is running. However combining both is something where I fail.
I use the following code to open an Excel file and put data in there:
Dim ExcelFileName As String
ExcelFileName = "C:\PictureTest.xlsx"
Dim Workbook As New Excel.Application
Dim DataWorkbook As New Excel.Workbook
Set DataWorkbook = Workbook.Workbooks.Open(ExcelFileName)
Workbook.Sheets("Sheet1").Cells(1, 1) = "Data to CELL"
DataWorkbook.Save
DataWorkbook.Close
Set Workbook = Nothing
Set DataWorkbook = Nothing
This one works perfectly, I can put data in any sheet anywhere I want. However I also need to put pictures on certain sheets/cells.
I use the following code to add a picture to the active Excel file from which I am running the VBA script:
Dim PicturePath As String
PicturePath = "C:\Picture.tif"
Dim strPath As String
Dim Picture As Object
Set Picture = ActiveSheet.Pictures.Insert(PicturePath)
Picture.ShapeRange.LockAspectRatio = msoCTrue
Picture.Placement = xlMoveAndSize
Picture.ShapeRange.Width = 0.3 * Picture.Width
Is there anyone who can help me in getting both combined?