Excel VBA Code – Inserting selected value from list

  Kiến thức lập trình

I’m having issues trying to get the selected worksheet to be inputted in the line of code

Set ws=ThisWorkbook.Sheets(SheetArray())

I’m new to coding especially in excel VBA and tried to merge two codes together.

I used the loop to have a list of the worksheets to be able to print from.

I need to be able to select from the same list and send an email of the selected information

I keep getting type mismatch, but don’t know how to fix it.

Please Help 🙂

Dim OutApp As Object
Dim OutMail As Object
Dim table As Range
Dim pic As Picture
Dim ws As Worksheet
Dim wordDoc


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

'insert report, convert to image, and cut

Dim i As Long, c As Long
   Dim SheetArray() As String
    
   With ActiveSheet.ListBoxSH
    For i = 0 To .ListCount - 1
    If .Selected(i) Then
    ReDim Preserve SheetArray(c)
    SheetArray(c) = .List(i)
    c = c + 1
   End If
  Next i
End With
On Error GoTo 0
'Sheets (SheetArray().Insert)
    
Set ws = ThisWorkbook.Sheets(SheetArray())
Set table = ws.Range("A1:O37")
ws.Activate
table.Copy
Set pic = ws.Pictures.Paste
pic.Width = 1000
pic.Height = 1000
pic.Cut

2

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website Kho Theme wordpress Kho Theme WP Theme WP

LEAVE A COMMENT