JamesT
12-14-2016, 08:10 PM
Hello,
My macro asks the user, via a dialog box, to select a folder to find where standard figures are saved, this happens every time the macro is opened - is there a way to run this macro once and 'save' the folder location in the macro to be used the next time the macro is executed (to bypass the user input section)? and if so, I need to expand this macro to identify if there is an error with opening this folder and re-run the 'select folder' macro if there is an error.
My code is here:
-----
Private Sub CommandButton1_Click()
Dim acontrol As Control
Dim intResult As Integer
Dim strPath As String
Dim a As String
Dim i As Long
Dim x As Variant
Dim m As String
Dim d As Integer
'Selection.EndKey Unit:=wdStory
'Selection.InsertBreak Type:=wdSectionBreakNextPage
Application.FileDialog(msoFileDialogFolderPicker).ButtonName = "Select Folder"
Application.FileDialog(msoFileDialogFolderPicker).Title = "Find the folder where the standard drawings are kept"
'the dialog is displayed to the user
intResult = Application.FileDialog(msoFileDialogFolderPicker).Show
'checks if user has cancled the dialog
If intResult <> 0 Then
a = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
End If
x = 1
For i = 1 To 26
For Each acontrol In Me.Controls
If acontrol.Name = "CheckBox" & i Then
If acontrol.Value = True Then
m = a & "\Checkbox" & x & ".jpg"
MsgBox m
Selection.EndKey Unit:=wdStory
Selection.InlineShapes.AddPicture FileName:=m
x = x + 1
Else
x = x + 1
End If
End If
Next acontrol
Next i
AddStandardDrawings.Hide
End Sub
My macro asks the user, via a dialog box, to select a folder to find where standard figures are saved, this happens every time the macro is opened - is there a way to run this macro once and 'save' the folder location in the macro to be used the next time the macro is executed (to bypass the user input section)? and if so, I need to expand this macro to identify if there is an error with opening this folder and re-run the 'select folder' macro if there is an error.
My code is here:
-----
Private Sub CommandButton1_Click()
Dim acontrol As Control
Dim intResult As Integer
Dim strPath As String
Dim a As String
Dim i As Long
Dim x As Variant
Dim m As String
Dim d As Integer
'Selection.EndKey Unit:=wdStory
'Selection.InsertBreak Type:=wdSectionBreakNextPage
Application.FileDialog(msoFileDialogFolderPicker).ButtonName = "Select Folder"
Application.FileDialog(msoFileDialogFolderPicker).Title = "Find the folder where the standard drawings are kept"
'the dialog is displayed to the user
intResult = Application.FileDialog(msoFileDialogFolderPicker).Show
'checks if user has cancled the dialog
If intResult <> 0 Then
a = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
End If
x = 1
For i = 1 To 26
For Each acontrol In Me.Controls
If acontrol.Name = "CheckBox" & i Then
If acontrol.Value = True Then
m = a & "\Checkbox" & x & ".jpg"
MsgBox m
Selection.EndKey Unit:=wdStory
Selection.InlineShapes.AddPicture FileName:=m
x = x + 1
Else
x = x + 1
End If
End If
Next acontrol
Next i
AddStandardDrawings.Hide
End Sub