![]() |
|
#1
|
|||
|
|||
|
Windows 10
Word (MS Office 2019) This is for local college course. I don't think the tutor knows either, to be honest ( )I'm trying to create a macro to replicate the attached file WEEKLY MENU - JMN.docx. I've tried numerous ways, techiques etc and spent hours recording but something goes wrong every time I've tried to run it. For what it's worth, I've been assigning Alt + 2 (deleting the previous attempt each time. Either the table goes wrong (specified 8 cols x 3 rows); used Table designs for the colouring, used mouse to change font, keyboard Ctrl+B/U for the formatting; title size 18 and table font 12. The bold doesn't always cancel after typing the title. I've highlighted each table cell to cancel Bold using 'shift and arrow keys' / and mouse, but neither have worked properly - characters come out in different cells etc and still in Bold!!! I'm now wondering if a macro for this is actually feasible. If so, how should I be doing it, please? Many thanks if you can help me
|
|
#2
|
|||
|
|||
|
Why on earth would you use a macro for this?
Just because it is an assignment?
Bold, in Word, is a toggle attribute. The Alt+F3 sounds like you want a macro to change this into a weekly table? |
|
#3
|
|||
|
|||
|
Quote:
Yes, purely an academic exercise. Certainly, a template would be more useful, in the 'real' world Quote:
Thanks. Yes, I frequently use Ctrl+B/U/I and have done for years. I just added this as detail, trying to explain some of what I tried, in case it was significant to the macro's failure I'd be pleased to learn if, and how, this can be achieved, as a macro. I'm now having my doubts. I can create macros with text, without a problem. I just can't seem to achieve this 'Weekly Menu' table, for whatever reason. Hope that explains OK
|
|
#4
|
|||
|
|||
|
I am moving this to the Word vba Forum.
Please clarify your question. Do you want your macro to create your sample? That is, a daily menu? Do you want your macro to create a weekly menu that is patterned after your example, i.e., one column per week? Do you want this to be a new document? Do you want this to be added to the end or at the beginning of an existing document? |
|
#5
|
|||
|
|||
|
Quote:
Thanks Charles My question is "Is creating a Macro, in Word, to reproduce the title "Weekly Menu' and table with the text, using the 'run' facility or assigned keystrokes, even possible?" I've made many attempts but have been unable to reporduce the 'image' as it should be. I'm actually wondering if it's even possible and, if it is, how to achieve this. please? Perhaps, someone with the knowledge/skills in using Word (only) could prove it's possible and to enlighten me as to how to do this, please. This is an assignment for an IT Skills course so purely an academic exercise to show the ability to create a Macro, in Word. I have emailed the tutor but not heard back, unfortunately. I appreciate, in real life, this would be better using a template but that's not the purpose of this exercise... I have no knowledge of VBA, or programming, either so it's not a matter of writing the code, not tweaking the resulting code, I'm afraid. Thanks very much. |
|
#6
|
|||
|
|||
|
Apologies ...
I've just noticed that my 'image' didn't work so I'll try again, so you can appreciate what I'm trying to replicate. |
|
#7
|
|||
|
|||
|
|
|
#8
|
||||
|
||||
|
For example:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, c As Long, r As Long, ArrDays, ArrMeals
ArrDays = Array("", "", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"): ArrMeals = Array("", "", "LUNCH", "DINNER")
With ActiveDocument.Range
.Font.Size = 18: .Font.Bold = True: .ParagraphFormat.Alignment = wdAlignParagraphCenter
.Text = "WEEKLY MENU" & vbCr & vbCr & vbCr
Set Tbl = .Tables.Add(Range:=.Characters.Last, Numrows:=3, NumColumns:=8)
End With
With Tbl
.Style = "Grid Table 5 Dark - Accent 6"
.Range.Font.Size = 10: .Range.Font.Name = "Arial": .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
For c = 2 To 8: .Cell(1, c).Range.Text = ArrDays(c): Next
For r = 2 To 3: .Cell(r, 1).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft: .Cell(r, 1).Range.Text = ArrMeals(r): Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#9
|
|||
|
|||
|
Thanks Paul
I appreciate your efforts but it isn't code that I need, it's how to achieve recording a macro to result in a replica of the image I attached. I'm currently trying it, avoiding using the mouse/track pad etc, and using only keystrokes, as I believe Macros don't always recognise actions via the mouse. Finding, and remembering, the specific keystrokes is proving difficult but I think I'm almost there. Although I like using keystrokes for more common actions, I don't feel it's realistic to use all the necessary keystrokes, in order to record different/various macros, in real life apart from the fact that this particular exercise, in real life, would surely be best in a template
|
|
#10
|
||||
|
||||
|
Your first post said:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#11
|
|||
|
|||
|
Again, thanks Paul
It's the title, table with text, that I need to create a macro, in order to replicate, demonstrating I can record the macro. I'm able to record macros but not this particular type of content, ie the table, formatting and text etc. I'm not expected to write VBA but to use the macro recording process. I can only think it doesn't work properly due to using mouse so I'm working on doing it all with keystrokes - definitely a challenge. It's purely academic, an exercise to demonstrate creating a macro so not for any other purpose. I was hoping someone, on this forum, would know what techniques etc were necessary to achieve this. Next class is Weds evening, so it will be interesting if the tutor can shed any light, apart from saying it's due to my computer!!! LOL |
|
#12
|
||||
|
||||
|
Here's a macro I recorded. Frankly, I can't see the point of demonstrating that you can record macros...
Code:
Sub Macro1()
'
' Macro1 Macro
'
'
Selection.EndKey Unit:=wdStory
Selection.Font.Bold = wdToggle
Selection.Font.Size = 18
Selection.Font.Underline = wdUnderlineSingle
Selection.Font.UnderlineColor = wdColorAutomatic
Selection.TypeText Text:="WEEKLY MENU"
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=3, NumColumns:= _
8, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
Selection.EscapeKey
Selection.Tables(1).Style = "Grid Table 5 Dark - Accent 6"
Selection.Tables(1).Select
Selection.Font.Bold = wdToggle
Selection.Font.Size = 10
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=8, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.Font.UnderlineColor = wdColorAutomatic
Selection.Font.Underline = wdUnderlineNone
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=7, Extend:=wdExtend
Selection.Font.UnderlineColor = wdColorAutomatic
Selection.Font.Underline = wdUnderlineSingle
Selection.TypeText Text:="Mon"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Tues"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Wed"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Thurs"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Fri"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Sat"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Sun"
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="LUNCH"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="DINNER"
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Font.UnderlineColor = wdColorAutomatic
Selection.Font.Underline = wdUnderlineNone
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#13
|
|||
|
|||
|
I appreciate what you're saying re having to demonstrate ability to record macros. However, this is for an IT Skills course and part of the assignments, which we must submit.
Copying code is not what the exercise is about, I'm afraid, especially when I don't understand VBA Thansk anyway |
|
#14
|
||||
|
||||
|
Well, if you step through the recorded macro I posted, you can see clearly enough the approach I took.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#15
|
|||
|
|||
|
OK, I'll give that a go, hopefully tomorrow, and see what I can make of it
I'll try to remember to get back to you to let you know how/if it helps me ![]() Thanks |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Please help me achieve this
|
Zeus | Word | 2 | 12-05-2015 09:54 AM |
| Can't achieve FULL JUSTIFICATION alignment in Word | Singh_Edm | Word | 20 | 11-20-2015 02:33 AM |
in project 2013 standard how to achieve multi-user editting?
|
Lorrainewjh | Project | 5 | 07-01-2015 05:57 PM |
| Must use VBA to achieve conditional formatting along with expanding table columns? | tinfanide | Excel | 0 | 06-10-2015 12:25 AM |
| How do you achieve Falling letters? | PPT | PowerPoint | 0 | 04-21-2012 06:12 AM |