PDA

View Full Version : I'm trying to do Magic! Not really....I want to create button macros in word



Just4Pier
02-14-2018, 01:21 PM
I'm trying to create a document for my daughter. In doing this I'm copying/pasting a lot of pictures from one document to another. So I guess what I'm needing is help doing the following:

1. create a macro in word and attach it to a button to switch between active documents easily. I need the VBA coding to do so something like "if docA=ActiveDocument, then make docB=Activedocument" and so on.

2. create a document by cutting/pasting into another document. I have to make some formatting changes when pasting into the new document and they are all uniform. You know like every pic I paste, I have to change the wrapping style to tight, change size to the same width and same height, then position at some point on the page. What would be the code to create a macro for that?

So any help with this would be greatly appreciated. Thanks in advance! :banghead::banghead::banghead:

macropod
02-14-2018, 02:16 PM
Ctrl-F6 switches between documents. No macros required for that.


If the pics are formatted in the source document with text wrapping, you should be able to select all of them in one go for copying, simply by selecting the first image, then holding down the Shift key as you select the others. After pasting, provided you don't change the selection, you should then be able to resize them all in one go. Again, no macros required. All you might still need to do is finalise the positioning.

Just4Pier
02-18-2018, 08:37 PM
Yes I know all that but I want to create a macro to shorten that process:

this is the first one I want:
1. insert picture
2. open picture folder dialog
3. select picture file name
4. link to file and save with the file
5. end

Just4Pier
02-18-2018, 08:41 PM
this is the first one I want:
1. insert picture
2. open picture folder dialog
3. select picture file name
4. link to file and save with the file
5. end

this is as far as I got with coding:
Sub PIXINS()
'
' PIXINS Macro
'
'
Selection.InlineShapes.AddPicture
FILENAME:=
LinkToFile:=False, SaveWithDocument:=True
End Sub


Help!!!!please

gmayor
02-18-2018, 10:19 PM
The following should work for you. This inserts a linked selected image. It is not clear what you want to save.


Option Explicit

Sub PIXINS()
'
' PIXINS Macro
'
'
Dim strName As String
strName = BrowseForImage("Select the image to insert")
If strName = "" Then Exit Sub
Selection.InlineShapes.AddPicture _
FileName:=strName, _
LinkToFile:=True, SaveWithDocument:=False
End Sub

Function BrowseForImage(Optional strTitle As String) As String
'Graham Mayor
'strTitle is the title of the dialog box
Dim fDialog As FileDialog
On Error GoTo err_Handler
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.Title = strTitle
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Iamge Files", "*.png,*.jpg,*.tif,*.bmp,*.gif"
.InitialFileName = Environ("USERPROFILE") & "\Pictures\"
.InitialView = msoFileDialogViewLargeIcons
If .Show <> -1 Then GoTo err_Handler:
BrowseForImage = fDialog.SelectedItems.Item(1)
End With
lbl_Exit:
Exit Function
err_Handler:
BrowseForImage = vbNullString
Resume lbl_Exit
End Function

gmayor
02-18-2018, 10:28 PM
See your other thread in this forum.

macropod
02-18-2018, 11:10 PM
Just4Pier: Kindly don't post questions about the same topic in multiple threads. I have merged the threads.