GetCurrWrd.Rd
Look for a running Word, resp. Excel instance and return its handle. If no running instance is found a new instance will be created (which will be communicated with a warning).
GetCurrWrd()
GetCurrXL()
a handle (pointer) to the running Word, resp. Excel instance.
When closing an application instance, the value of the pointer in R is not somehow automatically invalidated. In such cases the corresponding variable contains an invalid address.
Whether the pointer still refers to a valid running application instance can be checked by IsValidHwnd
.
if (FALSE) # Windows-specific example
# Start a new instance
GetNewWrd()
# grab the handle to this instance
wrd <- GetCurrWrd()
#> Loading required namespace: RDCOMClient
#> Warning: RDCOMClient is unfortunately not available for Linux systems (Windows-only).
# this should be valid
IsValidHwnd(wrd)
#> [1] FALSE
# close the instance
wrd$quit()
#> Error: attempt to apply non-function
# now it should be gone and the pointer invalid
if(IsValidHwnd(wrd)){
print("Ouups! Still there?")
} else {
print("GetCurrWrd: no running word instance found...")
}
#> [1] "GetCurrWrd: no running word instance found..."
# \dontrun{}