Forum

What is the differe...
 
Notifications
Clear all

What is the different between Dim vs Set?

7 Posts
3 Users
0 Reactions
404 Views
(@Anonymous)
Posts: 0
New Member Guest
 

Hi,

I saw the below coding from youtube. Anyone can help me to understand what is the different between "Dim" & "Set"?

Are we able copy the table in editor format?

Thank you.

 

Sub CopyPicture()
Dim mypicture As PowerPoint.Application
Set mypicture = New PowerPoint.Application

mypicture.Visible = msoTrue

Dim mypicture_pres As PowerPoint.Presentation
Set mypicture_pres = mypicture.Presentations.Add

Dim mypicture_slide As PowerPoint.Slide
Set mypicture_slide = mypicture_pres.Slides.Add(1, ppLayoutBlank)

Dim mychart As ChartObject

Range("B2:G12").Select
Selection.Copy

mypicture_slide.Shapes.PasteSpecial ppPasteBitmap

End Sub

 
Posted : 29/12/2019 4:33 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi,

Dim is used for declaring the object name and type, "Set" is to assign a value to it.

Set is used for objects only, not for all variables, for example:

Dim Rw as Long

Rw=54

 

What you have in that file is not a table, it's a colored range of cells that looks like a table.

Instead of pasting as image, try this:

mypicture_slide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoFalse

You can double click on it to edit.

 
Posted : 31/12/2019 2:08 am
(@Anonymous)
Posts: 0
New Member Guest
 

Thank you Catalin. With this editable coding, does it link to the original source file or mainly the table copy over to pptx?

I am not an expert in macro, still at learning stage. However, I am curious are we able to track how fast macro is running when we execute the coding/program? My manager always asked me to reduce my cycle time to process a report. I wonder how to show her the timing / speed when a macro run? Do you have any idea?

 Thank you.

 
Posted : 31/12/2019 4:01 am
(@catalinb)
Posts: 1937
Member Admin
 

As you can see, the line I sent has this: Link:=msoFalse
You can change it to true if you want to keep the link to original object.

At the beginning of your code:

Dim StartTime as double

StartTime=Now()

At the end of your code:

Msgbox "Elapsed time: " & Format((Now()-StartTime)/24/60/60,"hh:mm:ss")

 
Posted : 01/01/2020 12:56 am
(@Anonymous)
Posts: 0
New Member Guest
 

Hi Catalin,

Very helpful coding. I have tried it but the result showed as Elapsed time : 00:00:00. Does this mean the time is very fast not even 1 second?

Thank you.

 
Posted : 01/01/2020 3:29 am
(@debaser)
Posts: 836
Member Moderator
 

I think it should actually be:

MsgBox "Elapsed time: " & Format((Now() - StartTime), "hh:mm:ss")

 
Posted : 01/01/2020 5:31 am
(@Anonymous)
Posts: 0
New Member Guest
 

Thank you Velouria. It works well. 🙂

 
Posted : 02/01/2020 11:12 pm
Share: