mac excel vba 循环:来自列表 &然后导出为pdf [英] mac excel vba loop : from list & then export as pdf

查看:17
本文介绍了mac excel vba 循环:来自列表 &然后导出为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以迷失在这个:我在一张纸上有一个列表(学生名单),有 160 个学生号.想将每个学生编号粘贴到反馈表的单元格 A1 中,然后将其导出为 pdf 文件,并将学生编号作为文件名.走到这一步...干杯迈克

So lost myself in this: I have a list on one sheet (studentlist) that has 160 student numbers. Would like to paste each student number in cell A1 ion the Feedback sheet and then export as pdf to a file with the student number as the filename. Got this far... Cheers Mike

Sub Pdfexportmacro()

Dim rCell As Range
Dim rRng As Range
Dim SNum As Integer

'Student numbers in cells A7:A160, set to A7:A9 for testing
Sheets("studentlist").Activate
Set rRng = Range("A7:A9")

For Each rCell In rRng.Cells
     SNum = rCell.Value

     ' Write student number to cell A1 on Feedback sheet:
        Sheets("Feedback").Activate
        Range("A1").Activate
        ActiveCell.Value = SNum

       ' Export & save file as pdf using SNum as filename:
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "Macintosh HD:Users:Michael:Desktop:" & rCell.Value, Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=False

Next rCell

End Sub

推荐答案

我不是 MAC 用户,所以我可能会遗漏一些我在 Windows 操作系统中没有的限制,但您可能会遇到以下问题:

I'm not a MAC user so I may be missing some restrictions I don't have in Windows OS, but you may be after something like follows:

Option Explicit

Sub Pdfexportmacro()

    Dim rCell As Range, rRng As Range

    'Student numbers in cells A7:A160
    Set rRng = Worksheets("studentlist").Range("A7:A160") '<--| set your "students" range

    With Worksheets("Feedback") '<--| reference "Feedback" worksheet
        For Each rCell In rRng '<--| loop through "students" range
            .Range("A1").Value = rCell.Value '<--| write current student number to cell A1 on Feedback sheet

           ' Export & save file as pdf using SNum as filename:
            .ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
            "Macintosh HD:Users:Michael:Desktop:" & rCell.Value, Quality:= _
            xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
            OpenAfterPublish:=False
        Next rCell
    End With

End Sub

这篇关于mac excel vba 循环:来自列表 &amp;然后导出为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆