The design of stacks of layered materials in which adjacent layers interact by van der Waals forces[1] has enabled the combination of various two-dimensional crystals with different electrical, optical and mechanical properties, and the emergence of novel physical phenomena and device functionality[2-8]. Here we report photo-induced doping in van der Waals heterostructures (VDHs) consisting of graphene and boron nitride layers. It enables flexible and repeatable writing and erasing of charge doping in graphene with visible light. We demonstrate that this photo-induced doping maintains the high carrier mobility of the graphene-boron nitride (G/BN) heterostructure, which resembles the modulation doping technique used in semiconductor heterojunctions, and can be used to generate spatially-varying doping profiles such as p-n junctions. We show that this photo-induced doping arises from microscopically coupled optical and electrical responses of G/BN heterostructures, which includes optical excitation of defect transitions in boron nitride, electrical transport in graphene, and charge transfer between boron nitride and graphene.