Michael Alexander 및 John Walkenbach의 101 Ready-touse 매크로에서 얻은 코드를 사용하고 있습니다.범위 유형 값을 문자열 유형 변수로 전달하는 방법
이 코드에서는 범위 값을 코드에 지정합니다. 나는 사용자가 값을 선택할 수 있기를 원한다. 사용자가 성공적으로 범위 값을 입력하게 한 다음 오류가 발생합니다. 문제를 디버깅하는 데 도움이되도록 짧은 매크로를 작성하여 수행하려는 작업을 테스트했습니다. 하지만 메시지 상자에 정보를 전달하는 것처럼 보이지 않아서 작동한다는 것을 알 수 있습니다 (사용자가 입력란에 주소가 표시되는 범위가 선택 되었기 때문에 나타납니다). 알아낼 수 없습니다. 사용자가 입력 한 RANGE 유형을 가져 와서 내 메시지에 표시하거나 범위로 사용하려면 STRING 값으로 변환하는 방법. 이제 초보자로서, 나는이 작은 테스트가 디버깅을 배우는 데 도움이되는 원래의 문제보다 더 중요하다고 생각합니다.
는 (나는() UserRange는 String 형 예 UserRange = Rng1 인 경우와 Rng1 입력 범위 인 범위의 값을 할당 변형 AS로 AS 범위를 제조하고 StringVariable을 만들려고 노력 등 일부 다른 변화를 시도했다 : 다음은는
Sub SelectRange() Dim Rng1 As Range Set Rng1 = Application.InputBox("select cell", Type:=8) MsgBox ("You selected " & Rng1 & "as the range") End Sub
여기
가 원래의 코드였다 내 코드입니다 0Sub Macro101()
' I've already changed Step#4 to read the worksheet name instead of C20
' I'm now trying to change Step#3 to let the user select the range but
' I'm having problems using the input from the user becuase I've made that
' Variable as Range (Not shown here).
'Step 1: Declare your variables
Dim pp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim xlwksht As Excel.Worksheet
Dim MyRange As String
Dim MyTitle As String
Dim Slidecount As Long
'Step 2: Open PowerPoint, add a new presentation and make visible
Set pp = New PowerPoint.Application
Set PPPres = pp.Presentations.Add
pp.Visible = True
'Step 3: Set the ranges for your data and title
MyRange = "A1:J29"
'Step 4: Start the loop through each worksheet
For Each xlwksht In ActiveWorkbook.Worksheets
xlwksht.Select
Application.Wait (Now + TimeValue("0:00:1"))
MyTitle = xlwksht.Range("C20").Value
'Step 5: Copy the range as picture
xlwksht.Range(MyRange).CopyPicture _
Appearance:=xlScreen, Format:=xlPicture
'Step 6: Count slides and add new slide as next available slide number
Slidecount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(Slidecount + 1, ppLayoutTitleOnly)
PPSlide.Select
'Step 7: Paste the picture and adjust its position
PPSlide.Shapes.Paste.Select
pp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
pp.ActiveWindow.Selection.ShapeRange.Top = 100
'Step 8: Add the title to the slide then move to next worksheet
PPSlide.Shapes.Title.TextFrame.TextRange.Text = MyTitle
Next xlwksht
'Step 9: Memory Cleanup
pp.Activate
Set PPSlide = Nothing
Set PPPres = Nothing
Set pp = Nothing
End Sub
감사합니다. Tigeravatar. 당신은 오류 검사가 필요하다는 것에 대해 절대적으로 맞습니다. 나는 테스트를하는 동안 몇 번 나 자신을 취소했다. 나는 이것을 변경하려고하는 주 모듈에 포함시킬 것이다. – user2498217