Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Changing the default Pictures Path in Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hezviz - 30 Jan 2005 18:04 GMT
Hi.  I am brand new to this so please bear with me.  I have learned alot
from this group and have been able to get a lot accomplished. However, I
am stuck.

Here is the code I have so far:

Sub SetFillSpecific()
 Dim strName As String
 'display the InsertPicture dialog and
 'get the name of the selected picture.
 'use this value for the UserPicture value.
 
   Options.DefaultFilePath(wdPicturesPath) = "C:\Documents and
Settings\Heather.HEATHER-O49C7II\My Documents\My Pictures\MinPort\"
 
With Dialogs(wdDialogInsertPicture)
   
Display
   strName = .Name
   End With
   
   Selection.ShapeRange.Fill.UserPicture strName
End Sub

This works great when on my computer, but I need it to be able to work on
others computers.  I need to know how to make the path "C:\Documents and
Settings\Heather.HEATHER-O49C7II\My Documents\My Pictures\MinPort\" be a
dynamic path to wherever the My pictures folders is on any computer and
then also stipulate a specific folder within My Pictures such as Min
Port.

Can any one help?

Thank you so much.
Jonathan West - 30 Jan 2005 21:49 GMT
Hi Hezviz

Many stnadrd operati8ng system paths (including the My Pictures path for the
current user) can be found by the techniques described in the following
article

Using SHGetFolderPath to Find Popular Shell Folders
http://vbnet.mvps.org/code/browse/csidl.htm

Don't worry that the code sample is for VB6 and nor VBA. The sole change
that you would have to make to get the sample to work in VBA would be to
change the following line

Private Sub Form_Load()

to this

Private Sub UserForm_Initialize()

However, you will probably want to extract just the code from the sample
that you need for getting at My Pictures.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

> Hi.  I am brand new to this so please bear with me.  I have learned alot
> from this group and have been able to get a lot accomplished. However, I
[quoted text clipped - 30 lines]
>
> Thank you so much.
Hezviz - 31 Jan 2005 01:03 GMT
OK- that makes a little bit of sense but where do I add it to my existing
code to have the dialog box open in a subfolder of My pictures?
Jonathan West - 31 Jan 2005 01:41 GMT
> OK- that makes a little bit of sense but where do I add it to my existing
> code to have the dialog box open in a subfolder of My pictures?

You use it to set the value of Options.DefaultFilePath(wdPicturesPath)

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Hezviz - 31 Jan 2005 14:52 GMT
Thank you.  I really appreciate all your help. I am a beginning novice at
this.  So is this how my code should look?

Sub SetFillSpecific()
 Dim strName As String
 'display the InsertPicture dialog and
 'get the name of the selected picture.
 'use this value for the UserPicture value.
 
   Options.DefaultFilePath(wdPicturesPath) = "CSIDL_MYPICTURES " & _
               vbTab & "file" & _
               vbTab & "v5.0" & vbTab & "\My Documents\My Pictures"
     .ItemData(.NewIndex) = CSIDL_MYPICTURES
     
     With Dialogs(wdDialogInsertPicture)
   
Display
   strName = .Name
   End With
   
   Selection.ShapeRange.Fill.UserPicture strName
End Sub
Jonathan West - 31 Jan 2005 15:15 GMT
> Thank you.  I really appreciate all your help. I am a beginning novice at
> this.  So is this how my code should look?

Not quite.

1. Create a separate module, and paste the sample code into it from the
start of the code up to but not including the line "Private Sub Form_Load()"

2. Change this line

   Private Enum CSIDL_VALUES

to this

   Public Enum CSIDL_VALUES

3. Paste the following additional code into the module

Public Function GetFolderPath(csidl As Long) As String

  Dim buff As String
  Dim dwFlags As Long

 'fill buffer with the specified folder item
  buff = Space$(MAX_LENGTH)

  If SHGetFolderPath(0, csidl, -1, SHGFP_TYPE_CURRENT, _
                     buff) = S_OK Then
      GetFolderPath = TrimNull(buff)
  End If
End Function

Private Function TrimNull(startstr As String) As String
  TrimNull = Left$(startstr, lstrlenW(StrPtr(startstr)))
End Function

You now have a GetFolderPath function you can use anywhere else in your
code. Your main routine can now look something like this

Sub SetFillSpecific()
 Dim strName As String
 'display the InsertPicture dialog and
 'get the name of the selected picture.
 'use this value for the UserPicture value.

 Options.DefaultFilePath(wdPicturesPath) = _
     GetFolderPath(CISDL_MYPICTURES) & "\MinPort\"

 With Dialogs(wdDialogInsertPicture)

   If .Display = -1 Then
     strName = .Name
     Selection.ShapeRange.Fill.UserPicture strName
   Else
     MsgBox "User pressed cancel"
   End If
 End With

End Sub

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Hezviz - 31 Jan 2005 18:55 GMT
Thank you so very much- It is so much clearer now. I have learned a great
deal from you.  
Hezviz - 05 Feb 2005 17:59 GMT
I followed your instructions and I am missing something- I can't get this
to work.  What am I doing wrong?

Here is the code:

Public Enum CSIDL_VALUES
   CSIDL_DESKTOP = &H0
   CSIDL_INTERNET = &H1
   CSIDL_PROGRAMS = &H2
   CSIDL_CONTROLS = &H3
   CSIDL_PRINTERS = &H4
   CSIDL_PERSONAL = &H5
   CSIDL_FAVORITES = &H6
   CSIDL_STARTUP = &H7
   CSIDL_RECENT = &H8
   CSIDL_SENDTO = &H9
   CSIDL_BITBUCKET = &HA
   CSIDL_STARTMENU = &HB
   CSIDL_MYDOCUMENTS = &HC
   CSIDL_MYMUSIC = &HD
   CSIDL_MYVIDEO = &HE
   CSIDL_DESKTOPDIRECTORY = &H10
   CSIDL_DRIVES = &H11
   CSIDL_NETWORK = &H12
   CSIDL_NETHOOD = &H13
   CSIDL_FONTS = &H14
   CSIDL_TEMPLATES = &H15
   CSIDL_COMMON_STARTMENU = &H16
   CSIDL_COMMON_PROGRAMS = &H17
   CSIDL_COMMON_STARTUP = &H18
   CSIDL_COMMON_DESKTOPDIRECTORY = &H19
   CSIDL_APPDATA = &H1A
   CSIDL_PRINTHOOD = &H1B
   CSIDL_LOCAL_APPDATA = &H1C
   CSIDL_ALTSTARTUP = &H1D
   CSIDL_COMMON_ALTSTARTUP = &H1E
   CSIDL_COMMON_FAVORITES = &H1F
   CSIDL_INTERNET_CACHE = &H20
   CSIDL_COOKIES = &H21
   CSIDL_HISTORY = &H22
   CSIDL_COMMON_APPDATA = &H23
   CSIDL_WINDOWS = &H24
   CSIDL_SYSTEM = &H25
   CSIDL_PROGRAM_FILES = &H26
   CSIDL_MYPICTURES = &H27
   CSIDL_PROFILE = &H28
   CSIDL_SYSTEMX86 = &H29
   CSIDL_PROGRAM_FILESX86 = &H2A
   CSIDL_PROGRAM_FILES_COMMON = &H2B
   CSIDL_PROGRAM_FILES_COMMONX86 = &H2C
   CSIDL_COMMON_TEMPLATES = &H2D
   CSIDL_COMMON_DOCUMENTS = &H2E
   CSIDL_COMMON_ADMINTOOLS = &H2F
   CSIDL_ADMINTOOLS = &H30
   CSIDL_CONNECTIONS = &H31
   CSIDL_COMMON_MUSIC = &H35
   CSIDL_COMMON_PICTURES = &H36
   CSIDL_COMMON_VIDEO = &H37
   CSIDL_RESOURCES = &H38
   CSIDL_RESOURCES_LOCALIZED = &H39
   CSIDL_COMMON_OEM_LINKS = &H3A
   CSIDL_CDBURN_AREA = &H3B
   CSIDL_COMPUTERSNEARME = &H3D
   CSIDL_FLAG_PER_USER_INIT = &H800
   CSIDL_FLAG_NO_ALIAS = &H1000
   CSIDL_FLAG_DONT_VERIFY = &H4000
   CSIDL_FLAG_CREATE = &H8000
   CSIDL_FLAG_MASK = &HFF00
End Enum

Private Const SHGFP_TYPE_CURRENT = &H0 'current value for user, verify it
exists
Private Const SHGFP_TYPE_DEFAULT = &H1

Private Const MAX_LENGTH = 260
Private Const S_OK = 0
Private Const S_FALSE = 1

Private Declare Function lstrlenW Lib "kernel32" _
 (ByVal lpString As Long) As Long

Private Declare Function SHGetFolderPath Lib "shfolder.dll" _
  Alias "SHGetFolderPathA" _
 (ByVal hwndOwner As Long, _
  ByVal nFolder As Long, _
  ByVal hToken As Long, _
  ByVal dwReserved As Long, _
  ByVal lpszPath As String) As Long
 

'General Declarations code (form)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
 (ByVal hwnd As Long, _
  ByVal wMsg As Long, _
  ByVal wParam As Long, _
  lParam As Any) As Long

Private Const LB_SETTABSTOPS As Long = &H192

Public Function GetFolderPath(csidl As Long) As String

  Dim buff As String
  Dim dwFlags As Long

 'fill buffer with the specified folder item
  buff = Space$(MAX_LENGTH)

  If SHGetFolderPath(0, csidl, -1, SHGFP_TYPE_CURRENT, _
                     buff) = S_OK Then
      GetFolderPath = TrimNull(buff)
  End If
End Function

Private Function TrimNull(startstr As String) As String
  TrimNull = Left$(startstr, lstrlenW(StrPtr(startstr)))
End Function

'You now have a GetFolderPath function you can use anywhere else in your
'code. Your main routine can now look something like this

Sub SetFillSpecific()
 Dim strName As String
 'display the InsertPicture dialog and
 'get the name of the selected picture.
 'use this value for the UserPicture value.

 Options.DefaultFilePath(wdPicturesPath) = _
     GetFolderPath(CSIDL_MYPICTURES) & "\MinPort\"

 With Dialogs(wdDialogInsertPicture)

   If .Display = -1 Then
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.