# Load package and use exported macro, all within a macro

**URL:** <https://discourse.julialang.org/t/load-package-and-use-exported-macro-all-within-a-macro/65316>\
**Category:** General Usage\
**Tags:** question, macros\
**Created:** [July 26, 2021, 3:46pm UTC](https://discourse.julialang.org/t/load-package-and-use-exported-macro-all-within-a-macro/65316 "2021-07-26T15:46:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [July 26, 2021, 3:46pm UTC](https://discourse.julialang.org/t/load-package-and-use-exported-macro-all-within-a-macro/65316/1 "2021-07-26T15:46:35Z")

</div>

Can someone please explain why the following errors?

```julia
macro d(np::Integer)
    quote
        using Distributed
        addprocs($np)
        @everywhere begin
            using Pkg
            Pkg.activate(".")
        end
    end
end

julia> @d 2
ERROR: LoadError: UndefVarError: @everywhere not defined

```

(I often add the body of the macro as boiler-plate code when I want to parallelize my code, so I was hoping to write a macro to reduce the number of lines of code I have to add.)

If I split it into two macros (one with `using Distributed; addprocs($np)`, and the other with the `@everywhere` block) it works. It also works if I use `using Distributed` before calling `@d`.

I also don’t know why the call to `addprocs` doesn’t error. If `@everywhere` isn’t defined, I would expect `addprocs` to be undefined as well.
