Global Varible

  • Thread starter Thread starter Tyron
  • Start date Start date
T

Tyron

The refrence to this file, I would like to make a global Varible in the
begining of all my code
("G:\Tyronne Soanes\KaupPresBuilder\Testingc.ppt", msoFalse)

Somthing like Dim As [not too sure after this]

So this refrence would be lets say FL, how do I do it to that every
time it sees FL it calls ("G:\Tyronne
Soanes\KaupPresBuilder\Testingc.ppt", msoFalse)


Private Sub Columnssix3_Click()
If ActiveWindow.Selection.Type = ppSelectionSlides Then
Else
MsgBox "Must select a slide"
Exit Sub
End If
With Presentations.Open("G:\Tyronne
Soanes\KaupPresBuilder\Testingc.ppt", msoFalse)
.Slides(1).Shapes.Range(Array("Text Box 333", "Object333")).Copy
.Close
End With
ActiveWindow.Selection.SlideRange(1).Shapes.Paste
End Sub
 
Tyron,

2 things --
One: by declaring a constant outside of a sub-routine (at the top of the VBE
window) the variable will hold its value between sub routines.

So using this will work:
--------------
Option Explicit
Const MyFileName As String = "C:\Test.ppt"

Sub MyProcess()
MsgBox MyFileName
End Sub
----------------

The second part is that you will need to declare 2 constants for the two
parts of the variable you were trying to use. So this would work.

----------------
Option Explicit
Const MyFileName As String = "G:\TyronneSoanes\KaupPresBuilder\Testingc.ppt"
Const MyBoolean As Boolean = msoFalse

Private Sub Columnssix3_Click()
If ActiveWindow.Selection.Type <> ppSelectionSlides Then
MsgBox "Must select a slide"
Exit Sub
End If
With Presentations.Open(MyFileName, MyBoolean)
.Slides(1).Shapes.Range(Array("Text Box 333", "Object333")).Copy
.Close
End With
ActiveWindow.Selection.SlideRange(1).Shapes.Paste
End Sub
---------------


Does this help?


--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
yahoo2@ Please read the PowerPoint
yahoo. FAQ pages. They answer most
com of our questions.
www.pptfaq.com
..
..
 
Bill's suggestions are good. Depending on what you need to do, here's another approach: Create a function
that does what you want.

Function GetMyFile() as Presentation
' Opens your file and returns it as a presentation object
' Returns nothing if the file's not there
Dim sFile as string
sFile ="G:\Tyronne Soanes\KaupPresBuilder\Testingc.ppt"

' is the file there?
if len(dir$(sFile)) > 0 Then
Set GetMyFile = Presentations.Open(sFile, msoFalse)
end if
End Function

Then in your code:

With GetMyFile
' do your stuff
' you might want to include a check
if not GetMyFile Is Nothing Then

end if
End with

The refrence to this file, I would like to make a global Varible in the
begining of all my code
("G:\Tyronne Soanes\KaupPresBuilder\Testingc.ppt", msoFalse)

Somthing like Dim As [not too sure after this]

So this refrence would be lets say FL, how do I do it to that every
time it sees FL it calls ("G:\Tyronne
Soanes\KaupPresBuilder\Testingc.ppt", msoFalse)

Private Sub Columnssix3_Click()
If ActiveWindow.Selection.Type = ppSelectionSlides Then
Else
MsgBox "Must select a slide"
Exit Sub
End If
With Presentations.Open("G:\Tyronne
Soanes\KaupPresBuilder\Testingc.ppt", msoFalse)
.Slides(1).Shapes.Range(Array("Text Box 333", "Object333")).Copy
.Close
End With
ActiveWindow.Selection.SlideRange(1).Shapes.Paste
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top