为工作簿中的每个工作表运行vb代码

时间:2014-06-06 13:39:16

标签: excel vba excel-vba

我想调整这段代码,以便它:   - 用AlternativeText替换所有图像   - 运行工作簿中的所有工作表

    Dim Pic As Picture
    Dim Cell As Range
    For Each Pic In ActiveSheet.Pictures
        Set Cell = Pic.TopLeftCell.Offset(, -1)
        Do
            If Cell.Value = "" Then
                Cell.Value = Pic.ShapeRange.AlternativeText
                Exit Do
            Else
                Set Cell = Cell.Offset(1)
            End If
        Loop
    Next Pic
End Sub 

你能和我一起思考吗?非常感谢你提前!

1 个答案:

答案 0 :(得分:1)

要遍历工作簿中的所有工作表,请使用:

For s = 1 to ActiveWorkbook.Worksheets.Count
    Sheets(s).Activate

    'Enter code to be run on each worksheet here

Next s