Hi all,
the requirement is to add all the Screenshot present in a folder one by one to Excel sheet one after the other.
I am looping the folder and getting Screenshots and using Invoke code placing all into Excel sheet.
But the problem is the code I’m using is opening excel and pasting and closing excel for every image.I want the excel to be opened once and then insert all the image one after the other.I’m not good in vb code,can anyone please modify or guide me to do so.
Have attached the code screenshot
and below is the code
- filename =the path of the Excel file
- Sheetname=the excel sheet name
- Image path = Path of the image
4.CellReference= Cell value
Dim excel_raw As Microsoft.Office.Interop.Excel.Application
Dim wb_c As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
excel_raw=New Microsoft.Office.Interop.Excel.ApplicationClass
excel_raw.DisplayAlerts=False
excel_raw.Visible=True
wb_c=excel_raw.Workbooks.Open(filename)
ws=CType(wb_c.Sheets(sheetname),Microsoft.Office.Interop.Excel.Worksheet)
ws.Activate
Dim oRange As Microsoft.Office.Interop.Excel.Range=ws.Range(CellReference)
Dim left As Single=convert.ToSingle(oRange.Left)
Dim top As Single=convert.ToSingle(oRange.top)
Dim s As Microsoft.Office.Interop.Excel.Shape=ws.shapes.AddPicture(ImagePath,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue,Left,top,500,420)
ws.Range(“A:Z”).Columns.AutoFit()
wb_c.Save()
excel_raw.Quit()