├── example.gif ├── HelloWorld.docm ├── .gitignore ├── LICENSE ├── README.md └── JavaWord.bas /example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christophebedard/JavaWord/HEAD/example.gif -------------------------------------------------------------------------------- /HelloWorld.docm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christophebedard/JavaWord/HEAD/HelloWorld.docm -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.java 2 | *.class 3 | *.jar 4 | 5 | *.tmp 6 | 7 | # Word temporary 8 | ~$*.doc* 9 | 10 | # Excel temporary 11 | ~$*.xls* 12 | 13 | # Excel Backup File 14 | *.xlk 15 | 16 | # PowerPoint temporary 17 | ~$*.ppt* 18 | 19 | # Visio autosave temporary files 20 | *.~vsd* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 christophebedard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaWord 2 | 3 | Microsoft Word as a Java "IDE" 4 | 5 |

6 | 7 |

8 | 9 | ## Setup 10 | 11 | Set the path to Java's `\bin` (at the top in the macro). 12 | 13 | ## Use 14 | 15 | Copy or modify the provided `.docm` file. Alternatively, you can import the [macro](./JavaWord.bas) using any `.docm` file. 16 | 17 | Of course, make sure your Word document has the same name as your Java class! 18 | 19 | To build and run, click **Macros** under the **View** tab. Make sure **JavaWord** is selected, then click **Run**. 20 | 21 | ### Adding a shortcut to the quick access toolbar 22 | 23 | To add a shortcut to the macro in the quick access toolbar (as shown in the example above), follow these steps: 24 | 25 | 1. Right click on one of the icons at the top left (e.g. save, undo, redo) and select **Customize Quick Access Toolbar...** 26 | 27 | 2. Under **Chose commands from**, select **Macros** 28 | 29 | 3. Select the macro (should be **Project.NewMacros.JavaWord**), and click **Add >>** 30 | 31 | 4. (optional) To change the icon to the usual "run" icon (triangle), click **Modify...**, select the icon, and click **OK** 32 | 33 | 5. Click **OK** to close 34 | 35 | You can now run your code by simply clicking the newly added button! 36 | -------------------------------------------------------------------------------- /JavaWord.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "NewMacros" 2 | Sub JavaWord() 3 | ' JavaWord macro 4 | ' runs a Word file as Java code 5 | ' 6 | ' @author christophebedard 7 | 8 | Dim strDocName As String 9 | Dim strDocNameExt As String 10 | Dim intPos As Integer 11 | Dim strJavaPath As String 12 | Dim strCmd As String 13 | 14 | ' Set path to java bin 15 | strJavaPath = "C:\Program Files\Java\jdk-9.0.4\bin" 16 | 17 | ' Retrieve name of ActiveDocument 18 | strDocPath = ActiveDocument.Path 19 | strDocName = ActiveDocument.Name 20 | intPos = InStrRev(strDocName, ".") 21 | strDocName = Left(strDocName, intPos - 1) 22 | strDocNameExt = strDocName & ".java" 23 | 24 | ' Test if Activedocument has previously been saved 25 | If ActiveDocument.Path = "" Then 26 | ' If not previously saved 27 | MsgBox "The current document must be saved at least once." 28 | Else 29 | ' If previously saved, create a copy 30 | Set myCopy = Documents.Add(ActiveDocument.FullName) 31 | 32 | ' Force the file to be saved 33 | If myCopy.Saved = False Then myCopy.Save FileName:=strDocPath & "\" & strDocName 34 | 35 | ' Save file with new extension 36 | myCopy.SaveAs2 FileName:=strDocPath & "\" & strDocNameExt, FileFormat:=wdFormatText 37 | 38 | ' Close copy 39 | myCopy.Close 40 | End If 41 | 42 | ' Call command to 43 | ' 1- cd to current directory 44 | ' 2- Add java to PATH 45 | ' 3- Compile .java file 46 | ' 4- Run .java file 47 | strCmd = "cmd.exe /S /K" 48 | strCmd = strCmd & "CD " & strDocPath 49 | strCmd = strCmd & " & set PATH=" & strJavaPath & ";%PATH%" 50 | strCmd = strCmd & " & javac " & strDocNameExt 51 | strCmd = strCmd & " & java " & strDocName 52 | Call Shell(strCmd, vbNormalFocus) 53 | 54 | End Sub 55 | --------------------------------------------------------------------------------