Я пытаюсь извлечь график для конкретного человека в Excel и вставить его в документ Word.До сих пор мне удавалось извлечь график и ввести его в существующий документ Word, выделение конкретного графика для конкретного человека - это проблема, для которой мне не удалось найти решение.
Имена автоматически фильтруются, и при изменении значения имени график на листе также изменяется в соответствии с данными, относящимися к этому конкретному человеку.См. Изображение ниже, чтобы узнать, как настраиваются данные, которые меня интересуют.

Что бы я хотел сделать:
1. Loop through(and set) all values in the auto-filter drop-down.
2. Grab the graph for each of these people.
3. Insert it into a Word document.
Что я сейчас делаю:
(1. --Need help here--)
2. Grab the graph that is currently shown in the Excel sheet based on the name selected.
3. Insert it into a Word document
Я довольно новичок в VBA и большую часть кода ниже я нашел в интернете и изменил для своих нужд:
Private Sub CommandButton1_Click()
'Attempt to get all the values in the auto-filter drop-down
Dim c As Range
For Each c In Range(Cells(2, 2)).CurrentRegion.SpecialCells(xlCellTypeVisible)
MsgBox c.Value
Next c
'------- I was thinking of putting the code below in a loop for each of the names extracted from the auto-filter -------
'Name of an existing Word document, and the name the chart will have when exported.
Const stWordDocument As String = "WordDocument.docx"
Const stChartName As String = "Graph.png"
'Word objects.
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdbmRange As Word.Range
'Excel objects.
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim ChartObj As ChartObject
'Initialize the Excel objets.
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets("Sheet 1")
Set ChartObj = wsSheet.ChartObjects(1)
'Turn off screen updating.
Application.ScreenUpdating = False
'Export the chart to the current directory, using the specified name, and save the chart as a png
ChartObj.Chart.Export _
Filename:=wbBook.Path & "\" & stChartName, _
FilterName:="PNG"
'Initialize the Word objets to the existing Word document and bookmark.
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open(wbBook.Path & "\" & stWordDocument)
Set wdbmRange = wdDoc.Bookmarks("Graph").Range
'If there is already an inline shape, that means the macro has been run before - clean up any artifacts.
On Error Resume Next
With wdDoc.InlineShapes(1)
.Select
.Delete
End With
On Error GoTo 0
'Add the file to the document at the bookmarked location,
'and ensure that it is saved inside the Word doc.
With wdbmRange
.Select
.InlineShapes.AddPicture _
Filename:=wbBook.Path & "\" & stChartName, _
LinkToFile:=False, _
savewithdocument:=True
End With
'Save and close the Word document.
With wdDoc
.Save
.Close
End With
'Quit Word.
wdApp.Quit
'Clear the variables.
Set wdbmRange = Nothing
Set wdDoc = Nothing
Set wdApp = Nothing
'Delete the temporary file.
On Error Resume Next
Kill wbBook.Path & "\" & stChartName
On Error GoTo 0
MsgBox "Chart exported successfully to " & stWordDocument
End Sub
Надеюсь, мое объяснение понятно, заранее спасибо за любую помощь.