

The next issue is that your code is in Word and if you declare rng As Range then this is of type Word.Range and not Excel.Range and those are diffetent types so that is why you get a "Type Mismatch" error. You named your variable xlSheet but you load a workbook into it and not a worksheet. In existing modules Option Explicit needs to be added manually as first line.įurther I highly recommend to name your variables according what they contain because otherwise it gets very confusing.

This will add Option Explicit to new modules only. In the VBA editor go to Tools › Options › Require Variable Declaration. This is a good practice and will protect you from doing it wrong by notifying you of not declared variables: To activate it for all new codes that you add in the future, you can activate it directly in Excel and Word. This way it is less likely that you end up with unseen errors. I recommend to use Option Explicit and declare all your varibales properly. Notes: For this error, I tried to use for each loop as this is array but the error is showing before executing the for loop. The above line gives "Type Mismatch" error when running. Set rng = xlSheet.Worksheets(1).Range(ID_Range) The above line gives "Object required" error when running. Set rng = xlSheet.Worksheets(1).Range(ID_Range).Value2 When i try to get the values from the range of cells in excel, i got the following error for the code. I used this url to construct my skeleton code: 'Debug.Print VarType(xlSheet.Worksheets("Sheet1").Range("A3:A5").Value)ĭebug.Print VarType(xlSheet.Worksheets("Sheet1").Range(ID_Range).Value2) Offset_to_fetch = 1 'Select this to fetch comments etc. ID_Range = "A2:A6" 'Select this as range like "A2:A16" I have tried with multiple code snippets by google search but unable to construct the working macro. Repeat the same process for another table in Word document.Paste the value of Col2 in word table with cell position 10.Get text in Word table with cell position 3.
