Share via

ThisDocument.Path gives different path in mac VBA

Anonymous
2016-09-28T06:44:03+00:00

I am using Word VBA for mac project.

My document directory is "/Users/agnimac/Desktop/mac project/16Aug".

When I use ThisDocument.Path, it gives "Users/agnimac/Library/Containers/com.microsoft.Word/Data/Desktop/mac project/16Aug".

What is the problem? How to get original path of the active document?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2016-09-28T09:19:41+00:00

Use ActiveDocument.Path instead. The other, ThisDocument.Path, usually shows the path to the document where the macro resides. I'm going to guess that your macro is in the document and not in a template attached to it.

I say that because if the running macro was in your Normal template, ThisDocument.Path would provide the path to that template file. If the macro was in a custom template located somewhere on your computer, then ThisDocument.Path would show  that path. So, use ActiveDocument.Path if you want to know the location of the document and not its template.

That container path being shown is a Sandbox security area alias of your Desktop, which is why it looks so different. Why exactly this is happening if your macro is embedded in the document itself (".docm" format) as I believe it must be, I don't know, but will ask and see if someone on the Office Development Team will confirm.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2016-09-28T10:32:56+00:00

    Thanks Michaels.

    You are right...actually I was trying this code on .dotm file. it works for all docx files.

    Was this answer helpful?

    0 comments No comments