Sub Add_Macro_To_ThisWorkbook() Dim VBP As VBProject Dim VBM As VBComponent Dim VBModule As CodeModule Dim VBProc As VBComponent Set VBP = ActiveDocument.VBProject Set VBModule = VBP.VBComponents.Add(vbext_ct_StdModule).CodeModule 'Set VBModule = VBP.VBComponents.Item(1).CodeModule If ActiveDocument.PageSetup.Orientation = wdOrientPortrait Then VBModule.AddFromString ("Sub OrientMe" & vbCrLf & "ActiveDocument.PageSetup.Orientation = wdOrientPortrait " & vbCrLf & "End Sub") Else VBModule.AddFromString ("Sub OrientMe" & vbCrLf & "ActiveDocument.PageSetup.Orientation = wdOrientLandscape " & vbCrLf & "End Sub") End If End Sub